Reputation: 15
I have trouble with running my python app through script created by pip install. ModuleNotFoundError occurs for reasons which are hidden to me :/
#jsdc
Traceback (most recent call last):
File "/usr/local/bin/jsdc", line 6, in <module>
from src.sensor_data_collector import main
File "/usr/local/lib/python3.7/site-packages/src/sensor_data_collector.py", line 6, in <module>
from gatherer import Gatherer
ModuleNotFoundError: No module named 'gatherer'
Everything runs smoothly when I run the app directly through entry point:
python /usr/local/lib/python3.7/site-packages/src/sensor_data_collector.py
Project setup.py:
import os
import pathlib
import subprocess
from setuptools import setup, find_packages
from setuptools.command.install import install
HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
def run(self):
install.run(self)
current_dir_path = os.path.dirname(os.path.realpath(__file__))
create_service_script_path = os.path.join(current_dir_path, 'install_scripts', 'create_service.sh')
subprocess.check_output([create_service_script_path])
setup(
name="jacfal-sensor-data-collector",
version="0.0.1",
description="Collects data from iot sensors and sent them to defined target",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/Jacfal/SensorDataCollector",
author="Jacfal",
author_email="[email protected]",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.7",
],
packages=find_packages(),
entry_points={
"console_scripts": ["jsdc=src.sensor_data_collector:main", ]
},
)
Project file structure:
.
├── install_scripts
│ └── create_service.sh
├── install.sh
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
├── src
│ ├── configuration.py
│ ├── config.yml
│ ├── event.py
│ ├── gatherer.py
│ ├── helpers
│ │ ├── __init__.py
│ │ └── sensor_helpers.py
│ ├── __init__.py
│ ├── sensor_data_collector.py
│ ├── sensor.py
│ ├── sensors
│ │ ├── dummy_sensor.py
│ │ └── __init__.py
│ ├── targets
│ │ ├── influxdb_target.py
│ │ ├── __init__.py
│ │ └── log_target.py
│ └── target_system.py
└── tests
I am working with the setup.py for the first time, so I will be glad for any help or advice. Thanks.
Upvotes: 1
Views: 1602
Reputation: 133919
There is something missing from the picture. You do not seem to have a top-level package, and your distribution was built as if to have src
as the top level package name - try import src.gatherer
and it would "work".
Of course the proper fix is to have a proper top level package which means you need to make a directory inside src
(sensor_data_collector
perhaps?) and move all the files into that directory; and use find_packages('src')
. Then you need to prefix all the imports with this.
Upvotes: 2