How to find the latest *compatible* version of a Pypi package? - python

On a production server, I am forced to use python3.2. Sadly several of my dependencies require >=python3.4.
Is there a way to find out what the latest version of a package is that can be used with a specific python version?
For instance, with python3.2, what version of numpy should be used?
(This is only an example, answers would ideally not focus on the example, but on the actual question).

Perhaps you could use environment markers to solve the problem?
These are strings that can be used in requirements.txt and setup.py files (under the install_requires argument) and look like:
numpy>=1.7,<2; python_version > '3.4'
numpy>=1.7,<1.12; python_version < '3.4'
They can help you match packages to Python versions with some flexibility.

This should work with pip>=22.2 (tested with Python 3.10.8 + pip 22.2.2) and give you the latest version of a package compatible with a given Python version:
python -m pip install numpy --dry-run --python-version 3.2 --no-deps --target foo
Output:
Collecting numpy
Downloading numpy-1.12.1.zip (4.8 MB)
---------------------------------------- 4.8/4.8 MB 3.6 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Would install numpy-1.12.1
Extracted from this answer.

You can go to individual package and check requirement. Like for Numpy you can check on github which tells Python version 2.7 or >= 3.4 required.

Related

can't find my packages from pycharm/heroku

I have deployed a package into https://pypi.org/project/core-lib/0.0.1.dev1/
But pycharm or heroku can't find my package with this error message
Can you help me, please?
Thank you
Pycharm
No matching package version found: 'core-lib==0.0.1.dev1' (required: ==0.0.1.dev1, installed: <nothing>, latest: <nothing>)
heroku deploy
-----> Installing requirements with pip
ERROR: Could not find a version that satisfies the requirement core-lib==0.0.0.8 (from -r /tmp/build_c6b601b1/requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for core-lib==0.0.0.8 (from -r /tmp/build_c6b601b1/requirements.txt (line 1))
! Push rejected, failed to compile Python app.
! Push failed
Installed your package from pypi using PyCharm, and I am able to find it
(randomtesting) C:\Users\User\PycharmProjects\randomtesting>pip list
Package Version
---------------------- -------------------
core-lib 0.0.1.dev1
Perhaps the file was released into pypi very recently?
And I checked the link again, now it has the latest version.
Maybe try this?
pip install core-lib
You've declared that your package must be used under Python >= 3.7. Please make sure you use Python with high enough version. For example, I tried to install the package with Python 2.7 and pip failed to find the project. With Python 3.7 it was installed successfully.

pip using out of date package index

I am trying to install package inside a docker container(python:rc-slim).
As of now I see that most recent azureml-core wheel uploaded to PyPI is:
azureml_core-1.13.0-py3-none-any.whl
but when I run pip install azureml-core==1.13.0 I get following error:
ERROR: Could not find a version that satisfies the requirement
azureml-core==1.13.0 (from versions: 0.1.50, 0.1.57, 0.1.58, 0.1.59,
0.1.65, 0.1.68, 0.1.74, 0.1.80, 1.0rc83, 1.0rc85, 1.0.2, 1.0.6, 1.0.8, 1.0.10, 1.0.15, 1.0.17, 1.0.17.1, 1.0.18, 1.0.21, 1.0.23, 1.0.30, 1.0.33, 1.0.33.1, 1.0.39, 1.0.41, 1.0.41.1, 1.0.43, 1.0.43.1, 1.0.45, 1.0.48, 1.0.53, 1.0.55, 1.0.57, 1.0.57.1, 1.0.60, 1.0.62, 1.0.62.1, 1.0.65, 1.0.65.1, 1.0.69, 1.0.72, 1.0.74, 1.0.76, 1.0.76.1, 1.0.79, 1.0.81, 1.0.81.1, 1.0.83, 1.0.85, 1.0.85.1, 1.0.85.2, 1.0.85.3, 1.0.85.4, 1.0.85.5, 1.0.85.6, 1.1.0rc0, 1.1.1rc0, 1.1.1.1rc0, 1.1.1.2rc0, 1.1.2rc0, 1.1.5, 1.1.5.1, 1.1.5.2, 1.1.5.3, 1.1.5.4, 1.1.5.5, 1.1.5.6, 1.1.5.7)
When installing packages from 'apt-get' I usually have to update the index first but I can't find a comparable command to do that with pip.
azureml-core version 1.1.5.7 supports Python 2.7 and 3.4+.
Starting from version 1.2.0 it only supports Python 3.5+.
From your list of versions I can guess you use Python 2.7 or 3.4. To use a later version of azureml-core you need a later version of Python.
Two possibilities:
the package needs you to use an underscore (since hyphens don't behave) so pip can download it: so run pip install azureml_core==1.13.0
Run with the --no-cache-dir argument, so pip install --no-cache-dir azureml_core==1.13.0. This argument forces pip to refresh it's package cache.

Install specific version of setuptools as a dependency of package

My package has setuptools in dependencies. I am trying to restrict the version of setuptools when installing my package.
The package has following restriction in setup.py:
setup(
setup_requires=[
'setuptools==50.2.0',
'pip>=19,!=20.0,!=20.0.1,<21'
],
...
And it has the same restriction in pyproject.toml:
[build-system]
requires = ["setuptools==50.2.0", "pip>=19,!=20.0,!=20.0.1,<21", "wheel"] # PEP 508 specifications.
However, when installing my package with pip, it downloads the latest setuptools 50.3.0.
Why does it ignore the requirements? How can I make it not install the latest version?
I think you're getting confused about build time (setup_requires / pyproject.toml build-system requires) and installed time (install_requires). at install time, you're getting unpinned setuptools because it's a transitive dependency without version restrictions
setuptools is being pulled in via a transitive dependency in install_requires (notably: jsonschema):
$ visualize-requirements t.txt
cryptography>=2.4.2,<3
- cffi!=1.11.3,>=1.8
- pycparser
- six>=1.4.1
click>=7.0,<8
intelhex<3,>=2.2.1
python-jose<4,>=3.0.1
- pyasn1
- rsa
- pyasn1>=0.1.3
- ecdsa<0.15
- six
- six<2.0
jsonschema<4,>=3.0.0
- six>=1.11.0
- attrs>=17.4.0
- setuptools
- pyrsistent>=0.14.0
pyocd==0.27.3
- intervaltree<4.0,>=3.0.2
- sortedcontainers<3.0,>=2.0
- pylink-square
- six
- psutil>=5.2.2
- future
- cmsis-pack-manager>=0.2.7
- milksnake>=0.1.2
- cffi>=1.6.0
- pycparser
- appdirs>=1.4
- pyyaml>=3.12
- pyelftools
- six<2.0,>=1.0
- colorama
- prettytable
- pyusb>=1.0.0b2,<2.0
- pyyaml<6.0,>=5.1
- intelhex<3.0,>=2.0
cbor==1.0.0
imgtool==1.7.0a1
- intelhex>=2.2.1
- click
- cryptography>=2.4.2
- cffi!=1.11.3,>=1.8
- pycparser
- six>=1.4.1
- cbor>=1.0.0
I'm using visualize-requirements from a tool I wrote called requirements-tools
Seems accurate, 50.3.0 is greater than 40.0, less than 51, and not equal to 46.0 or 50.0. You may need to further restrict your requirements. If you know which version you want, just specify that explicitly
EDIT:
I created a fresh venv and checked pip list, seems like with a high enough version of pip, setuptools comes at 50.3.0.
$ pip3 -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 list | grep setup
setuptools (20.7.0)
You are using pip version 8.1.1, however version 20.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Inside the venv (assuming Python 3.x)
$ . vv/bin/activate
(vv) $ pip3 -V
pip 20.2.3 from /home/user/vv/lib/python3.5/site-packages/pip (python 3.5)
(vv) $ pip3 list | grep setup
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
setuptools 50.3.0
Thanks to the answers and comments I can make a conclusion.
To use a specific version of setuptools it is necessary to have it in both locations - in pyproject.toml and at the beginning of install_requires of setup.py.
The tool like pip will use the version from pyproject.toml to build the project. However, if there is any dependency that has the latest version of setuptools in its requirements, then the latest version will be used to install the dependency. Also, the environment will keep the version that was last installed.

How to get pip to tell me why it doesn't match PyPI binary wheels?

I'm building my own install of Python, then using pip to install some packages into it. I want to use the pre-built binary wheels for packages like Cryptography.
Python 2.7.15 / 2.7.16
Pip 19.0.3
Setuptools 40.8.0
On GNU/Linux is just works: it grabs the manylinux1 wheel and everything works just fine.
On MacOS, it refuses to download any of the binary wheels for most versions. I've added lots of -v options to pip, but all it says is:
$ mypython -s -u -m pip install -v --only-binary 'cryptography' 'cryptography==2.6.1'
...
Skipping link https://files.pythonhosted.org/packages/.../cryptography-2.6.1-cp27-cp27m-macosx_10_6_intel.whl#sha256=... (from https://pypi.org/simple/cryptography/) (requires-python:>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*); it is not compatible with this Python
...
Could not find a version that satisfies the requirement cryptography==2.6.1 (from versions: 1.0.1, 1.0.2, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.2.2, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.4, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.6, 1.7, 1.7.1, 1.8, 1.8.1, 1.8.2)
I've tried to understand why those particular versions are OK but not the latest, and the only thing I can see is that those versions have a specific x86_64 wheel package, while the later ones only have the fat binary intel wheel packages. My Python has a package definition of:
>>> import distutils.util
>>> distutils.util.get_platform()
'macosx-10.12-x86_64'
So I wondered if that was it. I modified my Python build to use MACOSX_DEPLOYMENT_TARGET=10.6 and added --enable-universalsdk=/ --with-universal-archs=intel to the configure line, and now my Python reports this:
>>> import distutils.util
>>> distutils.util.get_platform()
'macosx-10.6-intel'
However, I still get exactly the same messages from pip when I try to install.
So I'm wondering, is there any way I can get pip to be more informative and tell me exactly what about these binary packages it doesn't like, that is causing it to say "is not compatible" and skip them?
Thanks to a hint from #wim I found this command:
$ mypython
...
>>> from setuptools.pep425tags import get_supported
>>> for t in get_supported(): print(str(t))
...
This shows the full list of tuples used to match supported packages. Using this information I was able to compare it to the PyPI downloads and discover that I had built my MacOS Python with UCS4 support (which is common on Linux) where relatively few PyPI packages provide wide unicode binary wheels for MacOS.
I have no particular reason to prefer UCS4 so I switched my MacOS builds to UCS2 and it worked!
Hopefully this information will prove helpful to someone else.
Regarding the tags, recent versions of pip are able to output the full list of tags compatible with the currently running Python interpreter via the debug command:
$ path/to/pythonX.Y -m pip debug --verbose
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
[...]
Compatible tags: 87
cp38-cp38-manylinux2014_x86_64
cp38-cp38-manylinux2010_x86_64
cp38-cp38-manylinux1_x86_64
cp38-cp38-linux_x86_64
cp38-abi3-manylinux2014_x86_64
cp38-abi3-manylinux2010_x86_64
cp38-abi3-manylinux1_x86_64
cp38-abi3-linux_x86_64
cp38-none-manylinux2014_x86_64
cp38-none-manylinux2010_x86_64
cp38-none-manylinux1_x86_64
cp38-none-linux_x86_64
cp37-abi3-manylinux2014_x86_64
cp37-abi3-manylinux2010_x86_64
cp37-abi3-manylinux1_x86_64
cp37-abi3-linux_x86_64
[...]

Pip installs old version of package [duplicate]

This question already has answers here:
Why is pip installing an old version of my package?
(15 answers)
Closed 2 years ago.
Pip installs old version of my package
$ pip install pywps
Collecting pywps
Downloading pywps-3.2.6.tar.gz (123kB)
...
If you go to https://pypi.python.org/pypi/pywps/ the version 3.2.6 is not even mentioned there.
It's only mentioned at https://pypi.python.org/simple/pywps/
Any idea, why 3.2.6 is prefered over 4.0.0?
Thanks
P.S. Older responses do not seem to apply to this case.
If you run the command with a verbose option (and an up to date pip), you can see what's happening.
pip install -v pywps
It gives the following output:
1 location(s) to search for versions of pywps:
* https://pypi.python.org/simple/pywps/
...
Skipping link https://pypi.python.org/packages/f9/93/5c2c4c95e53b6193bf239ecc49cb859fd77d181311145edd13ba4cd39e09/pywps-4.0.0-py3.5.egg#md5=338eb2e56a36abc684800961b7e4ee0a (from https://pypi.python.org/simple/pywps/); unsupported archive format: .egg
...
Found link https://pypi.python.org/packages/c8/e6/8b88bc134f714f73e296466ab6b5b5a5ad96c44d35dcbcf41ccf9b76a283/pywps-3.2.6.tar.gz#md5=32bbbefacce633baa9147c74e4416c98 (from https://pypi.python.org/simple/pywps/), version: 3.2.6
Using version 3.2.6 (newest of versions: 3.2.6)
"GET /packages/c8/e6/8b88bc134f714f73e296466ab6b5b5a5ad96c44d35dcbcf41ccf9b76a283/pywps-3.2.6.tar.gz HTTP/1.1" 200 123280
Downloading pywps-3.2.6.tar.gz (123kB)
The egg file is ignored because .egg files are not supported in pip. They were supported by easy_install. I think the best solution is to start producing wheel files, which I think for pywps can be universal. If you also want to keep supporting the easy_install command, you can upload the tar.gz file or keep producing eggs.
You can install version 4.0.0 via pip straight from github:
sudo pip install git+https://github.com/geopython/pywps.git#master#egg=pywps

Categories

Resources