Pip install from pypi works, but from testpypi fails (cannot find requirements)
Update
PyPI has upgraded its site. According to the docs, the new advice is:
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple poirot
--index-url
points to your package on TestPyPI.--extra-index-url
points to dependencies on PyPI.poirot
is your package.
Out-dated
Try pip install --extra-index-url https://testpypi.python.org/pypi poirot
.
See also a reference post.
Can't install my own PyPi package: requirements can't be satisfied
You can have only one index but you can have as many extra indices as you wish. Add the main PyPI as an extra index:
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ my_package_name
First pip
looks into the index and then scan extra indices until it finds the package.
Numpy install requirement on package fails on pip install from PyPI but not from .whl
If you look at your error message, you can see
Downloading ... mathsom-0.1.1-py3-none-any.whl
So it is also using a whl file. However, the way numpy is installed differs. In your error message, it is clear that numpy
is trying to compile from source, which is not suprising, since you set the index to https://test.pypi.org/simple/
and there is only source distributions of numpy under that index. If you allow that the dependencies can be pulled from pypi, by setting test.pypi as an extra-index with --extra-index-url
then everything works (tested in a fresh conda env created with the command you have provided):
pip install --extra-index-url https://test.pypi.org/simple/ mathsom
Looking in indexes: https://pypi.org/simple, https://test.pypi.org/simple/
Collecting mathsom
Downloading https://test-files.pythonhosted.org/packages/4b/b3/76e6bbaa6c1da9f6f032e114af7f5724077154a28b5fc7069330185f2bc8/mathsom-0.1.1-py3-none-any.whl (18 kB)
Collecting scipy
Downloading scipy-1.5.4-cp36-cp36m-win_amd64.whl (31.2 MB)
|████████████████████████████████| 31.2 MB 393 kB/s
Collecting numpy
Downloading numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB)
|████████████████████████████████| 13.2 MB ...
Installing collected packages: numpy, scipy, mathsom
Successfully installed mathsom-0.1.1 numpy-1.19.5 scipy-1.5.4
Python Pip: pip install cannot find a version that satisfies a requirement - despite present in pyproject.toml
Main Error
TLDR; Pip tries to resolve dependencies with TestPypi, but they are in another index (Pypi). Workarounds at end of answer.
The fact that I am publishing to TestPypi is the reason this has happened. I will explain why what I did made this error appear, and then I will show how you, from the future, may solve this.
Difference between Pypi and TestPypi
Pypi is the Python Package Index. It's a giant index of Python packages one may install from with pip install
.
TestPypi is the Python Package Index designated for testing and publishing without touching the real Package Index. It can be useful in times when learning how to publish a package. The main difference is that it is a completely separate repository. Therefore, what's on TestPypi may not be exactly what's on Pypi.
My research was limited, so if I confused anyone, the main difference is that they are two different Package Indexes. One was made for testing purposes.
I published my package to TestPypi and set my pip install to install from that repository. Not Pypi, but TestPypi.
Why dependency resolution failed
When I defined my project's dependencies, I defined them based off of their Pypi presences. Most dependencies are present in Pypi. Not TestPypi. This meant that when I asked for my package from TestPypi, pip only looked at TestPypi, and the pip installer workflow fell out to a pattern like this:
0.5. Set fetching repository to TestPypi and Not Pypi.
- Pull package from TestPypi
- Install and examine dependencies
- Find first dependency (e.g. Beautifulsoup4)
- Pull dependency from TestPypi
- Successfully install Beautifulsoup4
-. This is because beautifulsoup4 is actually present in the TestPypi. - Move on to another dependency (e.g. rich)
- Fail to pull from TestPypi
-. Rich is not present in TestPypi. - Return dependency not found.
Why some dependencies oddly worked
As you see in workflow step 5., the beautifulsoup4 package was found on the TestPypi. (Someone had put it up there).
image to TestPypi page with beautifulsoup4
However, as you see in step 7., Rich is not found on the TestPypi index. This issue occurs because I set my repoistiroy to install from TestPypi because my that is where my package was held. This caused pip to use TestPypi. for every single dependency as well.
How I got around it.
I got around it by using TestPypi to verify accurate build artifact publishing, and then I jumped to Normal Pypi to test installation and dependency installation.
Workarounds
Install from TestPypi
python3 -m pip install -i https://test.pypi.org/simple/ <package name>
Install from Pypi (by default)
python3 -m pip install <package name>
Install package from TestPypi but dependencies from Pypi
The Python Docs explains this very well.
If you want to allow pip to also download packages from PyPI, you can specify --extra-index-url to point to PyPI. This is useful when the package you’re testing has dependencies:
python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ your-package
module on test.pypi can't install dependencies, even though they exist
-i URL
, or --index-url URL
means "use URL for installing packages from exclusively". By passing -i https://test.pypi.org/simple/
, you thus prohibit searching and downloading packages from PyPI (https://pypi.org/simple
). To use both indexes, use --extra-index-url
:
$ python -m pip install --extra-index-url https://test.pypi.org/simple/ sameWidther
pip install producing Could not find a version that satisfies the requirement
If you use --index-url
pip
will no longer install from "proper PyPI", but only from "test PyPI". If instead you use --extra-index-url
, it will install from both:
pip install --extra-index-url https://test.pypi.org/simple/ package_name_here
Related Topics
Calling Parent Class _Init_ with Multiple Inheritance, What's the Right Way
Print List Without Brackets in a Single Row
Proper Name for Python * Operator
I Can't Install Pyaudio on Windows? How to Solve "Error: Microsoft Visual C++ 14.0 Is Required."
How to Set Time Limit on Raw_Input
Remove Duplicate Dict in List in Python
Removing Duplicates from a List of Lists
Extracting Just Month and Year Separately from Pandas Datetime Column
Using Pandas to Pd.Read_Excel() for Multiple Worksheets of the Same Workbook
How to Keep Python Print from Adding Newlines or Spaces
Apply Function to Each Element of a List
Fast Punctuation Removal with Pandas
Convert Pyspark String to Date Format
Can't Start Foreman in Heroku Tutorial Using Python
Filter Dict to Contain Only Certain Keys