111

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?

brianmearns
  • 9,581
  • 10
  • 52
  • 79
  • Could not reproduce. `pip install -Iv tome==1.2.1.0-r4` installs for me (according to both the messages and `pip freeze` the package `tome==1.2.1.0-r4`. – David Robinson Jan 31 '13 at 01:51
  • It's probably still in your path somewhere? Try it with `-U` – Wolph Jan 31 '13 at 01:57
  • Hm..alright that's interesting. I've tried uninstalling it with pip, I guess I'll have to dig through some more and make sure it's all gone. Thanks for checking! – brianmearns Jan 31 '13 at 03:32
  • Looks like some kind of bug in pip. I have a similar issue, but I can't install an older version of django-tastypie. – simplylizz Mar 03 '13 at 18:15
  • related, I am having a similar issue with pip install -e https://stackoverflow.com/questions/69303363/why-is-an-old-version-of-a-package-of-my-python-library-installing-by-itself-wit – Charlie Parker Sep 23 '21 at 16:01

15 Answers15

122

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.

Ben Watson
  • 5,357
  • 4
  • 42
  • 65
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
  • Looks like this haven't been fixed yet. – Ale Sep 01 '13 at 12:45
  • 1
    @Ale110 It has been fixed - see my answer for details. – Piotr Dobrogost Sep 14 '13 at 08:59
  • 5
    FYI you can use `-vvv` instead of `-v -v -v`. – bfontaine Feb 02 '14 at 22:57
  • 9
    You can also use the `--no-cache-dir` flag instead of hunting down and deleting the file in `/tmp/`. – ethanabrooks Jan 27 '18 at 14:53
  • doing the pip install in my machine takes ages...how do I find the location of those files? I can see it the pip list but it doesn't point to the path. Any help? – Charlie Parker Sep 23 '21 at 15:54
  • According to `pip cache -h` output, it should theoretically be possible to do `pip cache remove ` instead of deleting a `/tmp/...` folder manually; haven't tested that, though - and if `pip` worked as expected, this page wouldn't even exist... – ssc Sep 21 '22 at 11:15
60

Try forcing download the package again with:

pip install --no-cache-dir --upgrade <package>
Iacchus
  • 2,671
  • 2
  • 29
  • 24
  • 1
    This has worked for me. Finally got v0.4 of photoutils installed over v0.2.1. Pip was downloading v0.4 tar but then it would just install (or keep) the v0.2.1. The --no-cache-dir and --upgrade flags finally did it! Thank you – scibuff Jun 19 '18 at 10:49
  • 5
    This is the right answer here. Pip keeps a cache of the relevant Pypi page for 600 seconds by default. So even if you remove the locally cached package, you've got to wait the 10 minutes for pip to fetch the new page with all the new version links. – brthornbury Sep 12 '18 at 04:56
  • 1
    This seems like a very logical answer. However, pip still installs get the same old version, even though the version I see via `pip search` is newer. – Mavamaarten Mar 10 '20 at 17:59
  • 1
    Try checking if it's something with virtualenv. Ah python versions. – Iacchus Mar 13 '20 at 06:05
  • does this work with editable mode e.g. `pip install -e --no-cache-dir --upgrade ~/ultimate-utils/ultimate-utils-proj-src`? – Charlie Parker Sep 23 '21 at 15:55
  • is the `--upgrade` needed? (for me I am doing `pip install -e ~/ultimate-utils/ultimate-utils-proj-src` – Charlie Parker Sep 23 '21 at 16:22
26

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)

Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • 5
    This should be marked as the correct answer. Upgrade pip like this: ```pip install -U pip``` – Emil Stenström Aug 11 '14 at 14:27
  • 3
    This fix still does not address pip silently using a cached version, which can be resolved using Iacchus's answer – Burrito Sep 21 '18 at 18:02
  • 2
    No, it does not seem to be fixed. I'm running into the same problem right now. – Regis May Mar 11 '20 at 15:25
  • Same here: Ten years on and I am running into the same issue; same problem in [this SO question](https://stackoverflow.com/q/67745900): `--pre` simply doesn't to make any difference when it comes to installing development versions. – ssc Sep 21 '22 at 12:08
17

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.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
simplylizz
  • 1,686
  • 14
  • 28
  • 2
    Thanks for the information. Any idea where I should look for the build directory? I tried deleting it from Python\Lib\site-packages, but the results were the same. I'm not executing the command from a location where the package exists or anything. – brianmearns Mar 05 '13 at 01:27
  • @sh1ftst0rm I'm using virtualenv under linux and for django-tastypie it was that: "$VIRTUAL_ENV/build/django-tastypie". Try to check top of the Python directory or just use search in your system. Also you could try to use "pip install -b ". – simplylizz Mar 05 '13 at 21:26
  • 1
    This doesn't appear to be my problem, I've searched far and wide and can't find any trace of the package or a build directory for it on my system. It must be some other bug in pip =(. Good tip anyway, I'm sure this will be the fix for a lot of people. – brianmearns Apr 05 '13 at 12:18
12

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
jkmartindale
  • 523
  • 2
  • 9
  • 22
ribozz
  • 576
  • 5
  • 8
6

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.

Ruth
  • 61
  • 2
  • 2
    +1 Thanks, this clued me into something important: pip relies on source distributions: with my latest version, I forgot to upload a source dist, so when I tried to install, it would only get the previous version. This doesn't solve my original problem, but it's helpful to know. – brianmearns Apr 05 '13 at 12:30
2

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

Alberto Chiusole
  • 2,204
  • 2
  • 16
  • 26
1

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
NateW
  • 2,856
  • 5
  • 26
  • 46
1

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.

jkmartindale
  • 523
  • 2
  • 9
  • 22
Cheen
  • 73
  • 7
1

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.

Tobias Uhmann
  • 2,757
  • 2
  • 25
  • 35
1

10 years on and pip still fails to work as expected .

I wasted a couple of hours now banging my head against the wall trying to find out why pip won't install a development version of my package. In my case, there are versions 0.0.4 and 0.0.5.dev1 in a private gitlab.com package registry (hence the --extra-index-url argument below), but I believe that's not relevant to the problem.

Following a lot of the advice on this page, I create a test venv in a far away folder, clear the pip cache, uninstall the package in question, etc. first to rule out the most common problems:

$ pip cache purge && \
  pip uninstall --yes my-package && \
  pip install --extra-index-url "https://_:${GITLAB_PASSWORD_TOOLS_VAULTTOOLS}@gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple" \
              --no-cache-dir  \
              --pre           \
              --upgrade my-package

output (using empty lines to separate output for commands):

WARNING: No matching packages
Files removed: 0

Found existing installation: my-package 0.0.4
Uninstalling my-package-0.0.4:
  Successfully uninstalled my-package-0.0.4

Looking in indexes: https://pypi.org/simple, https://_:****@gitlab.com/api/v4/projects/<project-id>/packages/pypi/simple
Collecting my-package
  Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/f07 ... 397/my_package-0.0.5.dev1-py3-none-any.whl (16 kB)
  Downloading https://gitlab.com/api/v4/projects/<project-id>/packages/pypi/files/775 ... 70e/my_package-0.0.4-py3-none-any.whl (16 kB)
    ...
Successfully installed my-package-0.0.4

So pip does see the dev package version, but chooses the earlier one nonetheless.

In an attempt to figure out what's going on, I published a 0.0.5 version: Error persists, pip sees all three versions, but still installs 0.0.4.

In a further, increasingly desperate attempt, I removed any versions prior to 0.0.5* from the gitlab.com package registry.

Only now, pip would bother to actually display some useful information:

$ (same command as above)
    ... (similar output as above) ...
ERROR: Cannot install my-package==0.0.5 and my-package==0.0.5.dev1 because these package versions have conflicting dependencies.

The conflict is caused by:
    my-package 0.0.5 depends on my-other-package<0.2.5 and >=0.2.4
    my-package 0.0.5.dev1 depends on my-other-package<0.2.5 and >=0.2.4

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

OK, so there is something wrong with my package dependencies. Thanks for letting me know.

Seriously - I tried hard for a couple of hours using all kinds of pip ... -vvv and/or fixed versions such as e.g. my-package==0.0.5.dev1 - but I did not manage to get any useful output out of pip - until I wiped the entire history from my package registry .

Hope this at least helps someone in the same situation.

ssc
  • 9,528
  • 10
  • 64
  • 94
0

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.

mlissner
  • 17,359
  • 18
  • 106
  • 169
0

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.
jarekwg
  • 375
  • 3
  • 8
0

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.

Mandera
  • 2,647
  • 3
  • 21
  • 26
0

if you need the path for your package do pip -v list. Example see related post when using pip -e Why is an old version of a package of my python library installing by itself with pip -e?

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323