Why is pip installing an old version of my package?

PythonPipSetuptools

Python Problem Overview


I've just uploaded a new version of my package to PyPi (1.2.1.0-r4): I can download the egg file and install it with easy_install, and the version checks out correctly. But when I try to install using pip, it installs version 1.1.0.0 instead. Even if I explicitly specify the version to pip with pip install -Iv tome==1.2.1.0-r4, I get this message: Requested tome==1.2.1.0-r4, but installing version 1.1.0.0, but I don't understand why.

I double checked with parse_version and confirmed that the version string on 1.2.1 is greater than that on 1.1.0 as shown:

>>> from pkg_resources import parse_version as pv
>>> pv('1.1.0.0') < pv('1.2.1.0-r4')
True
>>>

So any idea why it's choosing to install 1.1.0 instead?

Python Solutions


Solution 1 - Python

This is an excellent question. It took me forever to figure out. This is the solution that works for me:

Apparently, if pip can find a local version of the package, pip will prefer the local versions to remote ones. I even disconnected my computer from the internet and tried it again -- when pip still installed the package successfully, and didn't even complain, the source was obviously local.

The really confusing part, in my case, was that pip found the newer versions on pypi, reported them, and then went ahead and re-installed the older version anyway ... arggh. Also, it didn't tell me what it was doing, and why.

So how did I solve this problem?

You can get pip to give verbose output using the -v flag ... but one isn't enough. I RTFM-ed the help, which said you can do -v multiple times, up to 3x, for more verbose output. So I did:

pip install -vvv <my_package>

Then I looked through the output. One line caught my eye:

> Source in /tmp/pip-build-root/ has version 0.0.11, which satisfies requirement <my_package>

I deleted that directory, after which pip installed the newest version from pypi.

Solution 2 - Python

Try forcing download the package again with:

pip install --no-cache-dir --upgrade <package>

Solution 3 - Python

Thanks to Marcus Smith, who does amazing work as a maintener of pip, this was fixed in version 1.4 of pip which was released on 2013-07-23.

Relevant information from the changelog for this version

> Fixed a number of issues (#413, #709, #634, #602, and #939) related to > cleaning up and not reusing build directories. (Pull #865, #948)

Solution 4 - Python

I found here that there is a known bug in pip that it won't check the version if there's a build directory with unpacked sources. I have checked this on my troubling package and after deleting its sources from build directory pip installed the required version.

Solution 5 - Python

If you are using a pip version that comes with some distribution packages (ex. Ubuntu python-pip), you may need to install a newer pip version:

Update pip to latest version:

sudo pip install -U pip

In case of "virtualenv", skip "sudo":

pip install -U pip

Following command may be required, if your shell report something like -bash: /usr/bin/pip: No such file or directory after pip update:

hash -d pip

Now install your package as usual:

pip install -U foo

or

pip install foo==package.version.here

Solution 6 - Python

Got the same issue to update pika 0.9.5 to 0.9.8. The only working way was to install from tarball: pip install https://pypi.python.org/packages/source/p/pika/pika-0.9.8.tar.gz .

Solution 7 - Python

In my case the python version used (3.4) didn't satisfy Django 2.1 dependencies requirements (python >= 3.5).

Solution 8 - Python

For my case I had to delete the .pip folder in my home directory and then I was able to get later versions of multiple libraries. Note that this was on linux.

pip --version
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
virtualenv --version
15.1.0

Solution 9 - Python

Just in case that anyone else hassles with upgrading torchtext (or probably any other torch library):

Although https://pypi.org/project/torchtext/ states that you could run pip install torchtext I had to install it similiar to torch by specifying --find-links aka -f:

pip install torchtext===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

What irritated me was that PyCharm pointed me to the new version, but couldn't find it when attempting to upgrade to it. I guess that PyCharm uses its own mechanism to spot new versions. Then, when invoking pip under the hood, it didn't find the new version without the --find-links option.

Solution 10 - Python

I found that if you use microversions, pip doesn't seem to recognize them. For example, we couldn't get version 1.9.9.1 to upgrade.

Solution 11 - Python

In my case I am pip installing a .tar.gz package from Artifactory that I make a lot of updates to. In order to overwrite my cached Python files and always grab/install the latest I was able to run:

pip install --no-cache-dir --force-reinstall <path/to/tar.gz>

You should see this re-download any necessary files and install those, instead of using your local cache.

Solution 12 - Python

In my case, someone had published the latest version of a package with python2, so attempting to pip3 install it grabbed an older version that had been built with python3.

Handy things to check when debugging this:

  • If pip install claims to not be able to find the version, see whether pip search can see it.
  • Take a look at the "Download Files" section on the pypi repo -- the filenames might suggest what's wrong (in my case i saw -py2- there clear as day).
  • As suggested by others, try running pip install --no-cache-dir in case pip isn't bothering to ask the internet because it already has your answer locally.

Solution 13 - Python

I had hidden unversioned files under the Git tab in PyCharm that were being installed with pip install . even though I didn't see the files anywhere else.

Took a long time to find it for me, posting this in hope that it'll help somebody else.

Solution 14 - Python

if you need the path for your package do pip -v list. Example see related post when using pip -e https://stackoverflow.com/questions/69303363/why-is-an-old-version-of-a-package-of-my-python-library-installing-by-itself-wit/69304352#69304352

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrianmearnsView Question on Stackoverflow
Solution 1 - PythonMatt FenwickView Answer on Stackoverflow
Solution 2 - PythonIacchusView Answer on Stackoverflow
Solution 3 - PythonPiotr DobrogostView Answer on Stackoverflow
Solution 4 - PythonsimplylizzView Answer on Stackoverflow
Solution 5 - PythonribozzView Answer on Stackoverflow
Solution 6 - PythonRuthView Answer on Stackoverflow
Solution 7 - PythonAlberto ChiusoleView Answer on Stackoverflow
Solution 8 - PythonNateWView Answer on Stackoverflow
Solution 9 - PythonTobias UhmannView Answer on Stackoverflow
Solution 10 - PythonmlissnerView Answer on Stackoverflow
Solution 11 - PythonCheenView Answer on Stackoverflow
Solution 12 - PythonjarekwgView Answer on Stackoverflow
Solution 13 - PythonManderaView Answer on Stackoverflow
Solution 14 - PythonCharlie ParkerView Answer on Stackoverflow