Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

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

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?)

question from:https://stackoverflow.com/questions/65861705/how-to-build-a-python-package-with-dependency-on-other-custom-python-package

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...