I've made my first python project and uploaded it on GitHub.
Upon installation with pip, I get different errors based on whether, from the root directory, I execute
pip install .
or
pip install -e .
I was able to recreate this error by having a project with these elements:
Dir tree:
.
├── my_package
│ ├── __init__.py
│ ├── main.py
│ └── test.py
└── setup.py
main.py:
import my_package.test
test.py:
print("hello there!")
setup.py
from setuptools import setup, find_packages
setup(
name='my_package',
version='1.0.0',
description='Description of my package',
packages=find_packages(
where="my_package"
),
install_requires=[]
)
This would, after executing
pip install .
python3 my_package/main.py
give this error:
Traceback (most recent call last):
File "./my_package/main.py", line 1, in <module>
import my_package.test
ModuleNotFoundError: No module named 'my_package'
Said error does not appear when main is called by using
pip install -e .
python3 my_package/main.py
giving back the expected "hello there!".
I managed to fix the problem, understanding that the issue was having the main script inside of the package, while importing files from the package itself.
But I still do not understand why it would work anyway when setting up the package/app in development mode...
Question: Why does that happen?