On fresh Vagrant VM using box bento/centos-7 the following commands corrupt my pip installation:
yum update
yum install epel-release -y
yum install python-pip -y
/usr/bin/pip2 install --upgrade pip setuptools pyOpenSSL psycopg2-binary lxml
This fails at the end with
Downloading https://files.pythonhosted.org/packages/84/48/5c99d8770fd0a9eb0f82654c3294aad6d0ba9f8600638c2e2ad74f2c5d52/setuptools-52.0.0.tar.gz (2.1MB)
100% |████████████████████████████████| 2.1MB 821kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "setuptools/__init__.py", line 16, in <module>
import setuptools.version
File "setuptools/version.py", line 1, in <module>
import pkg_resources
File "pkg_resources/__init__.py", line 1367
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-GZrC3W/setuptools/
You are using pip version 8.1.2, however version 21.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
If I then upgrade Pip I notice that my Python is broken. After that all pip commands end with SyntaxError
[root@bkd-openam ~]# pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/9e/24/bc928987f35dd0167f21b13a1777c21b9c5917c9894cff93f1c1a6cb8f3b/pip-21.0.tar.gz
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Running setup.py install for pip ... done
Successfully installed pip-21.0
[root@bkd-openam ~]# /usr/bin/pip2 install --upgrade pip setuptools pyOpenSSL psycopg2-binary lxml
Traceback (most recent call last):
File "/usr/bin/pip2", line 9, in <module>
load_entry_point('pip==21.0', 'console_scripts', 'pip2')()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why is this? Is this a known issue with Python? How do I fix this?
BTW, CentOS 7 is a given, we cannot upgrade to CentOS 8 at this point. Also, we are using Ansible so using virtualenv I think for target nodes is recommended against by the Ansible community.
We can install Python 3 of course on target nodes but not all Ansible code is available for combination Python 3 with CentOS 7.
Can we use Pip 20? We would like to upgrade to the most recent version of Pip that still works and I think that is Pip 20. How do I prevent upgrade to Pip 21?
Upgrade Or Downgrade To Specific Pip Version If you want to upgrade or downgrade your version of pip to a specific version on a Mac, you can do this by adding a pip==<version> flag to the end of your update command.
Updating Pip When an update for pip is available, and you run a pip command, you will see a message that says, “You are using pip version xy. a, however version xy. b is available.” You can run “pip install --upgrade pip” to install and use the new version of pip.
You can get an older version (2.7) of get-pip.py
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
In my opinion, you should create a python2 virtualenv and install your python2 package in it, as well as pip2. For example, when I installed cuckoo sandbox, I did it like this:
virtualenv --python=python2 cuckoo/ # make your virtualenv folder with python2
cd cuckoo
source bin/activate
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py # get pip for python2
python2 get-pip.py # install pip in your virtualenv
pip install cuckoo # install your python2 package
Hope it will help.
This problem has to do with the fact that Python 2.7 reached end of its life and that the PIP community dropped support for it this month.
PIP displays deprecation notices such as
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
To fix this and continue with unsupported Python 2.7 you should not upgrade to the latest pip version but to a version < 21.
pip install --upgrade "pip < 21.0"
As PIP dropped support for Python 2.7 in result we are facing the above mentioned issue, following are the commands which actually worked for me on Ubuntu.
sudo apt-get remove --purge python-pip
sudo apt-get autoremove
sudo rm -f /usr/local/bin/pip
sudo easy_install pip==20.3.4
pip --version
Output: pip 20.3.4
Same can be achieved for CentOS by changing package manager name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With