How to build a Python package with dependency on other custom python Package?

Viewed 364

I have a Python project and I want to publish it to Pypi. Let's call it Package_main. I used some local/private/custom Python packages (Package_1 and Package_2) in Package_main.

In Package_main:

import Numpy, matplotlib     # import public packages
import Package_1, Package_2  # import private/local/custom packages

Note:
I installed Numpy and matplotlib by command pip install Numpy, matplotlib.
I installed Package_1 and Package_2 by command python setup.py develop in the corresponding directory. Because the two packages have not been built and published to Pypi yet.

I have tried to build Package_main and publish it to Pypi. But I found after I downloaded Package_main in a new environment and use it, error shows:

ModuleNotFoundError: No module named Package_1

It means that my local Package_1 and Package_2 are not included into the Package_main.

I am willing to publich Package_main along with Package_1 and Package_2. Can you tell me how to do it? (I know one method is to publich Package_1 and Package_2 seperately to Pypi and then use them the same way as how I use Numpy, but I think this method seems not elegant, do you have any other solutions?)

1 Answers

A package in python would ideally need an __init__.py file to qualify as a package. Given that you need to pull data under the same root, there needs to be an __init__.py at your root that holds all of the necessary imports to your files.

Related