Skip to content
Advertisement

Import homemade package without duplicating name

I’ve built a package which I distributed through PyPI.

The upload, download, installation, and the package itself, all work fine. My problem is that in order to run it I need to call the package name twice, which I want to avoid.

I want it to go like this:

JavaScript

But it only works like this:

JavaScript

Rather than having package_name be the same as module_name, or have two different names, I just one the one. I suppose its because of the way the project folder is structured, like so:

JavaScript

I guess what I’m asking is how can I structure my project folder so that I get neat usage in the form of:

JavaScript

Thanks in advance

Advertisement

Answer

This can be performed by importing module_name in package_name/package_name/__init__.py.

Given your exact structure, with:

JavaScript
JavaScript

Then you should be able to perform

JavaScript

from e.g. package_name/test.py.

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