Skip to content
Advertisement

PyPI personal module cannot be imported by other users or myself?

I am currently working on a rather simply Python module and I’ve been trying to publish it on PyPI all day. This is my first time doing it.

I’ve succesfully built it using python3 setup.py sdist bdist_wheel then done python3 -m twine upload --repository testpypi dist/* and twine upload dist/* and it is successfully uploaded as seen here. However, when me or my friends do pip install manhattandistance it installs the package, and when I try to import it using from manhattan distance import * as seen in my code:

JavaScript

However, it says that Import "manhattan_distance" could not be resolved. When I try reinstalling it using pip, it says that it already is installed, and when I make my way to that path I notice that only a .info is installed, while other modules have 2 folders, one with files inside and one for .info.

Screenshot from powershell: Screenshot from powershell

See that my module only has a .info folder dedicated?: See that my module only has a .info folder dedicated

I created all the necessary files:

JavaScript

My setup.py

JavaScript

My init.py

JavaScript

Advertisement

Answer

Try with: import manhattandistance

And then use as follow: manhattandistance.mandist()

ps: I suggest to have another file instead of putting it in the __init__.py

EDIT:

Place your code in a utils.py file. You will have a structure like this:

JavaScript

Change your settings by replacing package_dir to packages=setuptools.find_packages() (should be enough)

JavaScript

then you should be able to import the module with:

from manhattandistance.src.utils import mandist

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement