The project structure
my_package
├── my_package
│ ├── __init__.py
│ └── my_module.py
└── setup.py
The module my_module.py
has a single func
function I am attempting to import.
The setup.py
file has the following content.
from setuptools import setup, find_packages
setup(
name='my_package',
packages=find_packages(where='my_package'),
version='1.0'
)
The import API
I'm installing the package with:
virtualenv --python=/usr/bin/python3.8 venv
source venv/bin/activate
python my_package/setup.py install
To then import it with:
import my_package
from my_package import my_module
However, the second import fails with:
ImportError: cannot import name 'my_module' from 'my_package' (unknown location)
Further more, running dir(my_package)
reveals that indeed the my_module
name did not get imported.
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
Similar questions on SO
setup.py installed package can't be imported provided solution proved non sucessfull.
ImportError: cannot import name 'Serial' from 'serial' (unknown location) adding a __init__.py
file in my_package/my_package
didn't work.
Git repo
I've placed an example of the issue at GitLab