Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install specific package from specific index

Tags:

python

pip

pypi

I have built a package (let's call it mypackage) that depends on a well-known third-party module (namely pandas), available on PyPi. I've uploaded mypackage on a custom PyPi-like server (pypicustom). I'm struggling to install it on environments where all I have access to is a mirror to PyPi (let's call it pypiproxy).

pip install --index-url http://custompypi/ mypackage

does not work as pandas can't obviously be found.

pip install --index-url http://pypiproxy/ --extra-index-url http://custompypi/ mypackage

works until somebody uploads a package named mypackage on PyPi.

Closest I could come with is:

pip install --index-url http://custompypi/ --no-dependencies mypackage
pip install --index-url http://pypiproxy/ --extra-index-url http://custompypi/ mypackage

which does not feel right.

Any idea?

like image 484
wecx Avatar asked Mar 16 '26 08:03

wecx


1 Answers

Probably not the answer you’re wanting, but Poetry (a Python dependency/environment tool) handles your requirement really well.

Not only can you configure sources with different priorities but you can explicitly set the source for a package so then when you do a poetry install it pulls all the dependencies from the sources you specify. A pyproject.toml for your example:

[tool.poetry.dependencies]
...
mypackage = { version = "^0.22", source = "custompypi" }

[[tool.poetry.source]]
name = "custompypi"
url = http://custompypi/
priority = "explicit"

[[tool.poetry.source]]
name = "pypi-proxy"
url = http://pypiproxy/
priority = "default"
like image 151
Nath Avatar answered Mar 17 '26 22:03

Nath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!