Issue with find in setup.cfg | modules are not seen in path

Viewed 511

I've been trying to properly package my python codes, upload it on git, and install in on an virtual environment all of which I did and seem to work just fine. The issue is that once I pip install my code on the virtual environment, when I run my package as:

python3 -m mypackage

it raises an error suggesting none of the modules that I imported in my __main__.py (my package has one single directory that contains everything: __init__.py, __main__.py, module1.py, etc. ) are seen. However, once I "cd" into where the package is installed in the virtual environment, it can see all the modules and everything works. My guess is there's an issue with my setup.cfg file and I guess the "find" commands are not doing what they are supposed to do

Please also let me know if some other thing could be written more elegantly.

[metadata]
# replace with your username:
name = my_package
version = 0.0.1
author = my_name
author_email = name@email.com
description = 
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/myname/mypackage
project_urls =
    Bug Tracker = https://github.com/myname/mypackage/issues
classifiers =
    Programming Language :: Python :: 3
    License :: OSI Approved :: MIT License
    Operating System :: OS Independent

[options]
package_dir =
    = src
packages = find:
python_requires = >=3.6
install_requires =
    numpy > 1.0 
    opencv-python >= 4.0

[options.packages.find]
where = src
1 Answers

i had a similar issue and it troubled me for some days. In the end I understood that the problem was in the folder structure. If you use the find: function in setup.cfg then it will look for packages under /src but if you have only modules (like I had) it will not find anything.

You should should put your modules inside a folder with an __init__ file like so:

src
 |
 |-----package:
          |
          |------ __init__.py
          |------ module1.py
          |------ module2.py
          |------ ...

Note that when you will try import module1 for instance you will need to import with:

from package import module1
Related