Could not find a version that satisfies the requirement <package>

1,516,416

Solution 1

This approach (having all dependencies in a directory and not downloading from an index) only works when the directory contains all packages. The directory should therefore contain all dependencies but also all packages that those dependencies depend on (e.g., six, pytz etc).

You should therefore manually include these in requirements.txt (so that the first step downloads them explicitly) or you should install all packages using PyPI and then pip freeze > requirements.txt to store the list of all packages needed.

Solution 2

I had installed python3 but my python in /usr/bin/python was still the old 2.7 version

This worked (<pkg> was pyserial in my case):

python3 -m pip install <pkg>

Solution 3

Although it doesn't really answers this specific question. Others got the same error message with this mistake.

For those who like me initial forgot the -r: Use pip install -r requirements.txt the -r is essential for the command.

The original answer:

https://stackoverflow.com/a/42876654/10093070

Solution 4

After 2 hours of searching, I found a way to fix it with just one line of command. You need to know the version of the package (Just search up PACKAGE version).

Command:

python3 -m pip install --pre --upgrade PACKAGE==VERSION.VERSION.VERSION

Solution 5

Just a reminder to whom google this error and come here.

Let's say I get this error:

$ python3 example.py
Traceback (most recent call last):
  File "example.py", line 7, in <module>
    import aalib
ModuleNotFoundError: No module named 'aalib'

Since it mentions aalib, I was thought to try aalib:

$ python3.8 -m pip install aalib
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
ERROR: No matching distribution found for aalib

But it actually wrong package name, ensure pip search(service disabled at the time of writing), or google, or search on pypi site to get the accurate package name:

enter image description here

Then install successfully:

$ python3.8 -m pip install python-aalib
Collecting python-aalib
  Downloading python-aalib-0.3.2.tar.gz (14 kB)
...

As pip --help stated:

$ python3.8 -m pip --help
...
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.

To have a systematic way to figure out the root causes instead of rely on luck, you can append -vvv option of pip command to see details, e.g.:

$ python3.8 -u -m pip install aalib -vvv
User install by explicit request
Created temporary directory: /tmp/pip-ephem-wheel-cache-b3ghm9eb
Created temporary directory: /tmp/pip-req-tracker-ygwnj94r
Initialized build tracking at /tmp/pip-req-tracker-ygwnj94r
Created build tracker: /tmp/pip-req-tracker-ygwnj94r
Entered build tracker: /tmp/pip-req-tracker-ygwnj94r
Created temporary directory: /tmp/pip-install-jfurrdbb
1 location(s) to search for versions of aalib:
* https://pypi.org/simple/aalib/
Fetching project page and analyzing links: https://pypi.org/simple/aalib/
Getting page https://pypi.org/simple/aalib/
Found index url https://pypi.org/simple
Getting credentials from keyring for https://pypi.org/simple
Getting credentials from keyring for pypi.org
Looking up "https://pypi.org/simple/aalib/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/aalib/ HTTP/1.1" 404 13
[hole] Status code 404 not in (200, 203, 300, 301)
Could not fetch URL https://pypi.org/simple/aalib/: 404 Client Error: Not Found for url: https://pypi.org/simple/aalib/ - skipping
Given no hashes to check 0 links for project 'aalib': discarding no candidates
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
Cleaning up...
Removed build tracker: '/tmp/pip-req-tracker-ygwnj94r'
ERROR: No matching distribution found for aalib
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 281, in _get_abstract_dist_for
    req.populate_link(self.finder, upgrade_allowed, require_hashes)
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 249, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 926, in find_requirement
    raise DistributionNotFound(
pip._internal.exceptions.DistributionNotFound: No matching distribution found for aalib

From above log, there is pretty obvious the URL https://pypi.org/simple/aalib/ 404 not found. Then you can guess the possible reasons which cause that 404, i.e. wrong package name. Another thing is I can modify relevant python files of pip modules to further debug with above log. To edit .whl file, you can use wheel command to unpack and pack.

Share:
1,516,416

Related videos on Youtube

Gabriel
Author by

Gabriel

Updated on July 31, 2022

Comments

  • Gabriel
    Gabriel almost 2 years

    I'm installing several Python packages in Ubuntu 12.04 using the following requirements.txt file:

    numpy>=1.8.2,<2.0.0
    matplotlib>=1.3.1,<2.0.0
    scipy>=0.14.0,<1.0.0
    astroML>=0.2,<1.0
    scikit-learn>=0.14.1,<1.0.0
    rpy2>=2.4.3,<3.0.0
    

    and these two commands:

    $ pip install --download=/tmp -r requirements.txt
    $ pip install --user --no-index --find-links=/tmp -r requirements.txt
    

    (the first one downloads the packages and the second one installs them).

    The process is frequently stopped with the error:

      Could not find a version that satisfies the requirement <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2)) (from versions: )
    No matching distribution found for <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2))
    

    which I fix manually with:

    pip install --user <package>
    

    and then run the second pip install command again.

    But that only works for that particular package. When I run the second pip install command again, the process is stopped now complaining about another required package and I need to repeat the process again, ie: install the new required package manually (with the command above) and then run the second pip install command.

    So far I've had to manually install six, pytz, nose, and now it's complaining about needing mock.

    Is there a way to tell pip to automatically install all needed dependencies so I don't have to do it manually one by one?

    Add: This only happens in Ubuntu 12.04 BTW. In Ubuntu 14.04 the pip install commands applied on the requirements.txt file work without issues.

    • James111
      James111 almost 8 years
      Sometimes your Django project may depend on local brew packages. Double check you have these installed!
    • Derick Daniel
      Derick Daniel about 5 years
      i had the same issue, with 'python -m pip install flask' i was able to install it
    • Charlie Parker
      Charlie Parker over 2 years
      did you check the version of python your env is using matches the python reqs of the project? If not it seems you get this error. I fixed it with conda create -n my_anatome_env python=3.9; conda activate my_anatome_env for example then doing the pip install.
  • Gabriel
    Gabriel over 8 years
    So the only way to find out which all the requirements are is to freeze the installed packages in a working set up and then add everything in there to the requirements.txt file?
  • Simeon Visser
    Simeon Visser over 8 years
    @Gabriel: currently yes as many Python packages are installed by running a setup.py file which contains the dependencies that they need. This should get better once Python package become wheel files (pythonwheels.com) which allow you to gather a list of all needed packages without executing arbitrary code in setup.py files.
  • Gabriel
    Gabriel over 8 years
    Thanks for the explanation Simeon. One more thing if you don't mind: why does this not happen in Ubuntu 14.04 but it does in Ubuntu 12.04?
  • Simeon Visser
    Simeon Visser over 8 years
    @Gabriel: I'm not sure - in my experience pip always aborts when it can't find a package to install. That being said pip is actively being developed so it could be that you have a version that I haven't worked with.
  • Martino
    Martino about 5 years
    What does jupyter have to do with this??
  • Rizwan Javid
    Rizwan Javid about 5 years
    how can upgrading pip resolve the dependencies? It require dependencies in the calling directory.
  • sschuberth
    sschuberth almost 5 years
    @SimeonVisser, "[wheels] allow you to gather a list of all needed packages without executing arbitrary code", interesting, mind sharing how to actually do that (by now)?
  • Juan-Kabbali
    Juan-Kabbali about 4 years
    this happens when in setuptools there is python_requires='>=3.0' as requirement
  • Pavlos Ponos
    Pavlos Ponos about 3 years
    Yeah.... I was stuck for 2 hours because i was typing wrongly package's name. Thanks for the tip.
  • camposer
    camposer about 3 years
    In my case, if it helps someone. I was getting exactly the same error, trying to run: pip3 install json. Then realised that json is part of cpython, so it was already there not needed to be "installed"
  • crypdick
    crypdick almost 3 years
    an easy way to check whether this applies to you is to see if there's a directory mismatch between which python and which pip
  • Cory Kleiser
    Cory Kleiser over 2 years
    replacing pip with pip3 worked for me as well
  • Charlie Parker
    Charlie Parker over 2 years
    wish the error message told me it was due to a python version mistmatch. Why does it not say that explicitly?
  • Charlie Parker
    Charlie Parker over 2 years
    wish the error message told me it was due to a python version mistmatch. Why does it not say that explicitly?
  • Charlie Parker
    Charlie Parker over 2 years
    wish the error message told me it was due to a python version mistmatch. Why does it not say that explicitly?
  • Rajesh Swarnkar
    Rajesh Swarnkar about 2 years
    Better add one liner explaining the flags. -U, --upgrade: Upgrade all specified packages to the newest available version. And -i, --index-url <url>: Base URL of the Python Package Index (default pypi.org/simple).
  • James
    James about 2 years
    Worked like a charm!
  • Libby Lebyane
    Libby Lebyane about 2 years
    Usually, it's also incorrect version installation, be on the check for the releases of the package