Python Forum
ModuleNotFoundError when application is not installed via setup.py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ModuleNotFoundError when application is not installed via setup.py
#1
Hi there,

i've packaged my program and uploaded it to pypi. When installed via pip everything works flawlessly. However, when cloning the repository, installing all dependencies and running the main application (here: runner.py) i get a ModuleNotFoundError.

Error:
Traceback (most recent call last): File "dpp/runner.py", line 34, in <module> from dpp.core.argparse.ordered_multi_args import OrderedMultiArgs ModuleNotFoundError: No module named 'dpp'
I use following folder structure:

Output:
decoder-plus-plus ├── dpp │   ├── core │   ├── images │   ├── __init__.py │   ├── __main__.py │   ├── plugins │   ├── runner.py │   └── ui ├── LICENSE ├── MANIFEST.in ├── README.md ├── requirements.txt └── setup.py
setup.py
...
setup(
    ...
    entry_points={
        "console_scripts": [
            "dpp=dpp.runner:main",
        ]
    },
)
I fixed the error by adding following code at the beginning of runner.py:
# FIX #27: Add 'dpp' to python package path if not present. 
#          This may happen when dpp was not installed via setup.py.
DPP_PACKAGE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if DPP_PACKAGE_PATH not in sys.path:
    sys.path.append(DPP_PACKAGE_PATH)
However, i don't think that my approach is common practice and that there is a more elegant solution to this.

I hope that all makes sense.

Any help would be much appreciated!

Note: The complete source code can be found at github.
Reply


Messages In This Thread
ModuleNotFoundError when application is not installed via setup.py - by bytebutcher - Jan-07-2021, 05:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Libraries installed with pipenv, but ModuleNotFoundError returned jpncsu 2 3,090 Sep-06-2021, 07:24 PM
Last Post: jpncsu
  How to send data from a python application to an external application aditya_rajiv 1 2,230 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  Cannot package application using pip; ModuleNotFoundError axcore 0 1,617 Jan-28-2020, 01:08 PM
Last Post: axcore
  Trying to setup Python application, odd error Yoshimaster96 6 6,803 Oct-01-2017, 11:32 PM
Last Post: magnet

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020