Why is pip installing an old version of my package? - python

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?

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.

Try forcing download the package again with:
pip install --no-cache-dir --upgrade <package>

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)

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.

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

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.

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

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

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.

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.

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.

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.

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.

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.

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?

Related

Error "Invalid version: '0.23ubuntu1' (package: distro-info)"

Originally, my app crashed with error ERROR: Failed building wheel for pycairo (in the picture)
Failed to build pycairo
I tried to fix it by running several commands
sudo apt install libcairo2-dev
sudo apt install cloud-init
Gave the same error. No fix.
then I tried uninstalling the requirements.txt and reinstalled
pip uninstall -r requirements.txt
pip install -r requirements.txt
Did not solve the issue.
then I tried the below command, but I still got the same error "Failed building wheel for pycairo":
pip3 install --upgrade pip (from this thread: ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly
then I tried this command:
pip install --upgrade pip setuptools wheel
and I got this error in the picture: "Invalid version: '0.23ubuntu1'"
Invalid version: '0.23ubuntu1'
I tried to also delete this package but it's showing that package not found:
command I used: sudo apt-get remove distro-info
Error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'distro-info' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 283 not upgraded.
I searched for solutions but did not find any regarding the error "Invalid version: '0.23ubuntu1'". Now, when I run "flask run", I get error: -bash: /home/ktai/.local/bin/flask: No such file or directory
Would appreciate any help!
I tried several command lines but nothing worked
I learned from this answer that there is a "bug" with versions of setuptools causing this specific Invalid version: '0.23ubuntu1' error.
Despite seeing errors with all sorts of pip commands including pip install, I was surprised to see that this downgrade command (from the answer linked) appears to resolve the issue:
pip install --upgrade --user setuptools==58.3.0
Are you using ubuntu 20.04 by chance?
I had a similar issue but it had to do nothing with pycairo so the situation might be different for you.
The existence of distro-info (with a version not compliant to PEP-440) among my Python packages was leading to the error message from your post's title whenever i tried to install another package.
For me, this one helped: (so you were close with the apt-get remove...)
python3 -m pip uninstall -y distro-info
In my case, it seems like it didnt break anything important so i will keep it like this.
But there is no guarantee the same works for you as well. Also, you might get it back the next time you install packages from your requirements.txt file.
If I understood this thread correctly, there might be updates with a compliant version of this package depending on which Ubuntu version you are using.
This error arises from PEP 440 (Python Enhancement Proposal #440), which enforces conventions for naming of Python packages, and this error seems to really only happen on Debian-based distros like Ubuntu. For example, I have been trying to install a package via pip and get an error:
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '1.1build1' (package: distro-info)
So it's telling us that 1.1build1 is an invalid version name per PEP 440, and it's probably getting the distro-info package from, in my case, Ubuntu (came preinstalled).
I can get around this by using a Python virtual environment and not allowing it to use system-site-packages, sometimes called "global packages".
The solution is to remove the offending package and reinstall a version of it that meets PEP 440 requirements (e.g. following the "0.0.0" convention. "1.2.0" for example is fine, "1.2build3" is not).
pip uninstall -y distro-info
pip install distro-info==1.0
Additionally, within PyCharm, I can navigate to the Python Interpreter settings, choose the interpreter I am using from the Python Interpreter dropdown, and confirm that the version of distro-info it's trying to use is 1.1build1. To "upgrade" this to 1.0, I can double-click on the "1.0" under the "Latest Version" column and select "Install Package" from the modal that pops up.
If this or the above command to remove distro-info isn't working, you can use this same window to remove distro-info and then simply run pip install distro-info==1.0.
Thank you for all the answers. To answer my own question, I was finally able to fix the issue by updating all the required packages.
Now there are no updates needed, and the app works again.
0 updates can be applied immediately.
The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Meeting a pip requirement using an alternative module

I'm trying to install a python module, 'pyAudioProcessing' (https://github.com/jsingh811/pyAudioProcessing) on my Linux Mint distribution, and one of the items in requirements.txt is causing issues: python-magic-bin==0.4.14. When I run pip3 install -e pyAudioInstaller, I get an error:
ERROR: Could not find a version that satisfies the requirement python-magic-bin==0.4.14 (from pyAudioProcessing==1.1.5) (from versions: none)
ERROR: No matching distribution found for python-magic-bin==0.4.14 (from pyAudioProcessing==1.1.5)
The same error appears if I try to manually install the module using pip3 install python-magic-bin. The module installs without issues on my windows machine.
pypi.org lets me download files for it manually, however only Windows and MacOS .whl files are available. I tried simply removing the requirement from the list, but that resulted in a large number of other errors to appear, so I assume the module is legitimately required.
Thee is another module called python-magic-debian-bin that I can download. Is there a simple way to convince pyAudioInstaller to use this other module instead of the original? Like can I somehow rename python-magic-debian-bin to python-magic-bin and hope it works out?
python-magic-bin 0.4.14 provides wheels for OSX, w32 and w64, but not for Linux. And there is no source code at PyPI.
You need to install it from github:
pip install git+https://github.com/julian-r/python-magic.git
As for pyAudioProcessing I can see 2 ways to install it:
Clone the repository and edit requirements/requirements.txt, replace python-magic-bin==0.4.14 with pip install git+https://github.com/julian-r/python-magic.git#egg=python-magic;
Install requirements manually and then install pyAudioProcessing without dependencies:
pip install --no-deps pyAudioProcessing
or
pip install --no-deps git+https://github.com/jsingh811/pyAudioProcessing.git
The library has updated the requirements very recently for it to work on Linux.
pip install -U pyAudioProcessing
Should get it all set up for you.
Alternatively, https://github.com/jsingh811/pyAudioProcessing the readme describes other getting started methods as well.

Pip installing wrong version on win7,

I have a package that I am trying to install via pip install allen-bradley-toolkit. The package is failing with the following reason.
The problem seems to related to the fact that pip is trying to install 1.0a1.post0 instead of the latest release version 2.0.0. Does anyone have any ideas on what to do about this. Perhaps there is something wrong in my deployment script. You can view the Github Library here to see how I am deploying to PyPi.
There is an issue opened on the GitHub Tracker #2 that you can also reference for more info.
NOTE: The package seems to install fine on my win10 machine. But I am unable to get it to install on a win7 VM.
Ive also tried installing with the following commands:
pip install --no-cache-dir allen-bradley-toolkit
pip install allen-bradley-toolkit==2.0.0 -> this ones throws a 'doesnt exist error`
At https://pypi.python.org/pypi/allen-bradley-toolkit/2.0.0 I see that the wheel is only available for Python 3. You're trying to install it with Python 2.7.
To publish a universal wheel (suitable for both Py2 and Py3) you need to set
[bdist_wheel]
universal = 1
in setup.cfg or run
python setup.py bdist_wheel --universal
The 2nd line of the output has a clue to the problem - "Using cached ..."
You can skip the cache using the --skip-cache --no-cache-dir option to pip install or request an upgrade using the -U option
edit: updated comment with the correct option (although, seems like that wasn't the problem in this specific case).

pyhdf links in PyPI going to server that is offline? (with workaround)

I am trying to use pip to add the package pyhdf in python3.
I'm working in a virtualenv and have the prereq packages there:
% pip list
numpy (1.9.2)
pip (7.0.3)
requests (2.7.0)
setuptools (17.0)
wheel (0.24.0)
If I ask pip to get the latest/default version of pyhdf, I believe it searches this index page
https://pypi.python.org/simple/pyhdf/
This appears to trip up pip, as it tries to FTP the egg for v.0.7.x (not the latest) from a server that is not presently responding:
ftp://nordet.qc.dfo-mpo.gc.ca/pub/soft/pyhdf/pyhdf-0.7-1.tar.gz
I've been through the whole mess that the 'requests' package doesn't accept FTP URLs like this one, and that pip now strongly discourages getting external/unverified packages even though they are listed at PyPI. I settled on this workaround, getting the latest build directly from the authors' site:
wget http://hdfeos.org/software/pyhdf/pyhdf-0.9.0.tar.gz
To build the python package from a downloaded egg, you need to get the source headers for libhdf before running setup.py (via pip or manually.) The following I did outside the venv, though they might work within one too
sudo apt-get install libhdf4-0
sudo apt-get install libhdf4-dev libhdf4-doc
Finally, back in the venv, the actual pip install syntax that worked for me to install pyhdf from the tar.gz that I had downloaded:
pip install --global-option=build_ext --global-option="-I/usr/include/hdf" --no-index --find-links=file:pyhdf-0.9.0.tar.gz pyhdf
after which pip list yields:
numpy (1.9.2)
pip (7.0.3)
pyhdf (0.9.0)
requests (2.7.0)
setuptools (17.0)
wheel (0.24.0)
Yay!
Since I'm posting my workaround that got me pyhdf okay, to make this an actual question I will ask:
Is there an official proper way that users can do to contact either PyPI admins or the authors of the pyhdf package to report that the "best match" link at the project page is:
no longer the latest release, and
points to an FTP server that is apparently offline (at least currently)
making pip install pyhdf basically infeasible without much extra manual intervention (which if permanent, ought to be documented by the maintainers)

What's the difference between direct pip install and the requirements.txt?

I'm confused. I've got a working pip install command (meaning: it installs a version of a library from Github which works for me), and I have a non-working (meaning: it installs a version of a library which does not work for me) way of putting that requirement into a requirements.txt file.
More concrete:
If I type on the command line
pip install -e 'git://github.com/mozilla/elasticutils.git#egg=elasticutils'
and then test my program, all works fine. If I put this line into my requirements.txt:
-e git://github.com/mozilla/elasticutils.git#egg=elasticutils
and then run my program, it breaks with an error (only the library should have changed, so I guess sth has changed in that library between the two versions).
But shouldn't both versions do exactly the same?? (Of course I've done my best to remove the installed version of the library between the two tests again, using pip uninstall elasticutils.)
Any information welcome …
Yep, as I wrote in my comment above, there seems to be a dependency-override when the requirements.txt states different than the dependencies in the packages. In my case installing the package manually also installed the (newer) version of requests, namely 1.2.0. Using the requirements.txt always installed (due to the override) the version 0.14.2 of requests.
Problem solved by updating the requests version in the requirements.txt :-)
Well I don't know exactly what's the difference, but when I want something to be installed from the requirements.txt and it's a git repo I do the following line:
#git+https://github.com/user/package_name.git
and then installing as following:
pip install -r requirements.txt

Categories

Resources