Install specific version of setuptools as a dependency of package - python

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.

Related

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.

Pip dependency issue : error: httplib2 0.15.0 is installed but httplib2<0.10,>=0.8 is required by set(['apache-beam'])

when trying to install python project, python setup.py install
I get the error,
error: httplib2 0.15.0 is installed but httplib2<0.10,>=0.8 is required by set(['apache-beam'])
However, looking at the pip dependencies
Imrans-MacBook-Pro:appengine imran$ pip freeze | grep httplib2
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: Could not generate requirement for distribution -ix 1.13.0 (/usr/local/lib/python2.7/site-packages): Parse error at "'-ix==1.1'": Expected W:(abcd...)
WARNING: Could not generate requirement for distribution - x (/usr/local/lib/python2.7/site-packages): Parse error at "'-===x'": Expected W:(abcd...)
google-auth-httplib2==0.0.3
httplib2==0.9.2
Could you please let me know from where it is taking the version 0.15.0, and why it is not using 0.9.2 instead ?

How to get Ansible on Fedora 30 to see modules

I installed Ansible 2.8.2 using dnf on Fedora 30. I have an Ansible plug-in that requires a library. Using pip3 install I installed the required library.
When I run ansible-playbook directly, I see a ModuleNotFoundError for that module.
But if I run python3 /usr/bin/ansible-playbook, the module is found.
How can I get Ansible as installed by dnf to see this library?
Edit: further info: as installed from dnf, the main Ansible script has a shebang for /usr/bin/python3 -s. If I remove the -s, this problem is solved.
What's the benefit that the repo maintainers were seeking in adding this -s flag?
Is there a case to be made for asking the repo maintainers to omit the flag?
How can I get pip3 to install the library I need into a directory that will be seen when the -s flag is in effect?
Edit: Here's the output of ansible --version, and thanks for asking.
ansible 2.8.2
config file = /home/jdashton/proj/ansible-ccharacter/ansible.cfg
configured module search path = ['/home/jdashton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.4 (default, Jul 9 2019, 16:32:37) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
This is different from the suggested duplicate question because that question describes a "remote" task being run on localhost, in which case Ansible uses the default "remote" python interpreter. In this question, the library is being called from a local plugin, under Ansible's own python process. The -s flag in the shebang line at the top of the /usr/bin/ansible script is preventing Ansible from seeing some local libraries.
Edit: Following the suggestion from #zigarn I tried removing the library and reinstalling it as root. This resulted in the library being reinstalled into the same directory /usr/local/lib/... as before. Is there a way to get pip3 to install into the system library?
Here are the commands I attempted:
# pip3 uninstall tenacity
Uninstalling tenacity-5.0.4:
Would remove:
/usr/local/lib/python3.7/site-packages/tenacity-5.0.4.dist-info/*
/usr/local/lib/python3.7/site-packages/tenacity/*
Proceed (y/n)? y
Successfully uninstalled tenacity-5.0.4
# pip3 install tenacity
Collecting tenacity
Using cached https://files.pythonhosted.org/packages/6a/93/dfcf5b1b46ab29196274b78dcba69fab5e54b6dc303a7eed90a79194d277/tenacity-5.0.4-py2.py3-none-any.whl
Requirement already satisfied: six>=1.9.0 in /usr/lib/python3.7/site-packages (from tenacity) (1.12.0)
Installing collected packages: tenacity
Successfully installed tenacity-5.0.4
# pip show tenacity
Name: tenacity
Version: 5.0.4
Summary: Retry code until it succeeeds
Home-page: https://github.com/jd/tenacity
Author: Julien Danjou
Author-email: julien#danjou.info
License: Apache 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: six
Required-by:
Also, for clarity, here is the source for the Ansible installation:
# dnf list ansible
Last metadata expiration check: 0:09:48 ago on Mon 12 Aug 2019 11:12:58 AM EDT.
Installed Packages
ansible.noarch 2.8.2-1.fc30 #updates
According to the documentation -s option of python is "Don’t add the user site-packages directory to sys.path."
So I would guess that you did pip3 install as your user instead as root, so the library was installed at your user side instead of system wide.
Try to reinstall the library with pip3 as root and it should be ok.

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

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.

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