Search code examples
pythonmatplotlibpippypi

Pip does not install dependencies declared in setup.py with install_requires


In a Python project, I am using install_requires in my setup.py as follows.

install_requires=['numpy', 'scipy', 'matplotlib']

I then create the source, binary and wheels as follows.

python setup.py sdist bdist bdist_wheel

When I publish, I use twine.

twine upload --repository dist/testpypi mypackage-0.1.1-py2-none-any.whl

In a Python 2.7 conda environment, I then attempt to test the install.

pip install -i https://test.pypi.org/simple/ mypackage==0.1.1

However, I get the following error message:

ERROR: Could not find a version that satisfies the requirement matplotlib (from mypackage) (from versions: none)
ERROR: No matching distribution found for matplotlib (from mypackage)

When I do a pip list and conda list, indeed, there is no matplotlib package listed.

What am I doing wrong? I thought (this point is where my understanding breaks down) that install_requires would list the prerequistes and pip install would pick up on that and automatically install the requirements? However, it seems that install_requires is acting as a guard against installing a package if its declared dependencies are not already installed.

In some internet searches, they seem to suggest that I include a requirements.txt via MANIFEST.in (e.g. include requirements.txt) and then pip install will auto-install the dependencies. However, after trying that approach, I still get the same error message. I tried with requirements.txt as follows.

matplotlib

And also as follows.

matplotlib>=2.2.3

How do I configure/setup setup.py and my distribution such that pip install or conda install will auto-install the declared dependencies via install_requires?


Solution

  • The problem is that pip looks for packages in same repository as selected package. So if you provide to use https://test.pypi.org/simple/ then it looks here for packages instead on https://pypi.org/simple/.

    U think that you need to use --extra-index-url parameter

    --extra-index-url <url>     Extra URLs of package indexes to use in addition to --index-url. Should follow the same rules as --index-url.
    

    So try:

    pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ mypackage==0.1.1