How To Solve Python Pip broken with sys.stderr.write(f“ERROR: {exc}”) error in my Vagrant VM using box bento/centos-7 .
Here is I am Adding All Possible solutions that I have tried to Solve This Error. Without wasting your time, Let’s start this article.
How Python Pip broken wiith sys.stderr.write(f“ERROR: {exc}”) error occurs ?
I Have Installed Python in my CentOs-7. I want to update my pip. So I just use pip install –upgrade pip this command to update my pip.
when I upgrade Pip I notice that my Python is broken. After that all pip commands end with SyntaxError.
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
here is I am Adding All Possible solutions that I have tried to Solve This Error.
How to solve Python Pip broken wiith sys.stderr.write(f“ERROR: {exc}”) ?
Question : How to solve Python pip broken with sys.stderr.write(f”ERROR: {exc}”) ?
Answer: This Problem Is Caused due to PIP community dropped support to 2.7. So You just have to upgrade pip to latest version.
Solution 1
This Problem Is Caused due to PIP community dropped support to 2.7. So You just have to upgrade pip to latest version.
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"
Solution 2
You can get an older version (2.7) of get-pip.py
curl https://bootstrap.pypa.io/2.7/get-pip.py --output get-pip.py
Summery
So it’s all About All possible solutions. Hope this above all solution helped you a lot. Comment below Your thoughts and your queries. Comment Below on your suggestion.
Hi, I tried above solution but doesn’t work in my case.
Traceback (most recent call last):
File “/usr/local/bin/pip”, line 11, in
load_entry_point(‘pip==21.0.1’, ‘console_scripts’, ‘pip’)()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 2843, in load_entry_point
return ep.load()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 2434, in load
return self.resolve()
File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 2440, in resolve
module = __import__(self.module_name, fromlist=[‘__name__’], level=0)
File “/Library/Python/2.7/site-packages/pip-21.0.1-py2.7.egg/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f”ERROR: {exc}”)
^
SyntaxError: invalid syntax
You can get an older version (2.7) of get-pip.py
curl https://bootstrap.pypa.io/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/2.7/get-pip.py –output get-pip.py # get pip for python2
python get-pip.py # install pip in your virtualenv
pip install cuckoo # install your python2 package
Awesome.. Solution 2 worked for me… Thanks a lot…