Tuesday 24 November 2020

package_dir in setup.py not working as expected

I'm trying to let users write code as a python module (folder with __init__.py defined) under whatever folder name they see fit. After that I want to install that module as a python package but define the import name myself.

The folder structure would be like this:

project_name/
    user_defined_name/
        __init__.py
        ...
    setup.py

According to this I should be able to add this to my setup.py to get it working:

setuptools.setup(
    package_dir={'my_defined_name': 'user_defined_name'},
    packages=['user_defined_name']
)

But the only way that I was able to access the code was by using import user_defined_name. I tried installing the package without -e but that gave the same result. Leaving the packages=['..'] out of the setup functions also did not change the result.

My question is kind of the same as this one and there the only answers seem to be to change folder names and that is something that I would like to avoid. That question mentioned that it might be due to a problem in setuptools but that seemed fixed 3 years ago.



from package_dir in setup.py not working as expected

No comments:

Post a Comment