On a 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, without using virtual environments or upgrading the OS or Python version?
Can I use Pip version 20 in this Python installation? How do I prevent upgrade to Pip 21?
For the equivalent issue with installing pip
in old Python installations, see Installing pip is not working in python < 3.6.
12
Answers
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
To fix this and continue with unsupported Python 2.7 you should not upgrade to the latest pip version but to a version < 21.
You can get an older version (2.7) of 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:
Hope it will help.
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.
Same can be achieved for CentOS by changing package manager name.
If this logic is used in a (e.g.) Github Actions matrix of different Python versions, the following bash snippet will determine if pip should be updated before pip 21.0 or not. For instance, Python 3.5 should not update beyond pip 21.0, but Python 3.6 can use more recent versions.
these commands solved for me on ubuntu 20.04 LTS:
summarized from https://linuxhint.com/install_python_pip_tool_ubuntu/ and https://unix.stackexchange.com/a/631283 by editin 5th command
remove the pip and reinstall it, on ubantu16.04
Its version conflict issue. first check python –version, below steps for python version 2.7
Update: Please use following command to install the pip on python2.7
Enjoy it!
When you tried to upgrade pip it was upgraded to version 21 and as written in the link: Python2-support
So now you first need to remove the current pip installed, which you can do from
Centos 7:
Now we will install
pip
againNow we will upgrade pip to the supported version
Now
pip
command will work fineEnvironment
Ubuntu 16.04 LTS 32-bit.
Python 3.5
I was getting the error running these commands:
The
python3
is just a symlink topython3.5
:Python 3.9
Another error is thrown:
Solution: Python 3.6
These commands solved the problem for me:
This helped me (Ubuntu 16.04)
In general I removed completely pip and pip3 like:
Search pip and remove files and directories. In my case it was:
Then I installed pip3 once again:
Python 3.5
Python 3.6
I’m reporting my solution because it worked for me on MacOS (not on Linux, which these other solutions were for). Hopefully this will help someone in case they have a problem similar on Mac. I’m running MacOS 11.4. PIP got broken on my system somehow. My global system is supposed to be using Python3 but I was getting the error message:
My solution was running this:
Now PIP is working again on my system.