pip: sys.stderr.write(f"ERROR: {exc}") with Python 3.5 [duplicate] - python

This question already has answers here:
Installing pip is not working in python < 3.6
(6 answers)
Closed 2 years ago.
i am having a trouble with pip and pip3.
I am trying to install requirements and it shows an error. When i write pip3 or pip --version it show this error.
jumphost#jumphost-VirtualBox:~$ pip3 --version
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import __main__
File "/usr/local/lib/python3.5/dist-packages/pip/__main__.py", line
21, in <module>
from pip._internal.cli.main import main as _main
File
"/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
If i am trying to install, it showed this
jumphost#jumphost-VirtualBox:~/kubespray$ pip install -r requirements.txt
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import __main__
File
"/usr/local/lib/python2.7/dist-packages/pip-21.0-py2.7.egg/pip/__main__.py",
line 21, in <module>
from pip._internal.cli.main import main as _main
File
"/usr/local/lib/python2.7/dist-packages/pip-21.0-py2.7.egg/pip/_internal/cli/main.py",
line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
jumphost#jumphost-VirtualBox:~/kubespray$ pip3 install -r requirements.txt
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import __main__
File "/usr/local/lib/python3.5/dist-packages/pip/__main__.py", line
21, in <module>
from pip._internal.cli.main import main as _main
File
"/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
I didn't found a right answer so this is the reason why i ask you. Thanks !
I tried remove python, pip, python3 and pip3 multipletimes but still same problem.

pip has dropped support for Python 2 and 3.5. You will need to use a version-specific branch, assuming that your Python version is 3.5:
curl -fsSL https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.5
get-pip.py reference: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
Related: How can I install a legacy PIP version with python 2.6.6 or python 2.7.5?
Better yet, as suggested in the comments, install a newer version of Python that is not end-of-life.

Related

"SyntaxError: invalid syntax" while installing Setuptools

I needed to install Setuptools for a project I was doing, and I had to download Setuptools through a .tar file (don't ask), but when ran the command I needed to use to install it:
C:\Users\myname\Downloads\setuptools-51.1.1>py -2 setup.py install
It ended up with a SyntaxError:
Traceback (most recent call last):
File "setup.py", line 7, in <module>
import setuptools
File "C:\Users\myname\Downloads\setuptools-51.1.1\setuptools\__init__.py", line 16, in <module>
import setuptools.version
File "C:\Users\myname\Downloads\setuptools-51.1.1\setuptools\version.py", line 1, in <module>
import pkg_resources
File "C:\Users\myname\Downloads\setuptools-51.1.1\pkg_resources\__init__.py", line 1365
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax
I'm using Python 2.7.
Why is it showing the error, and how can I fix it?
Edit:
When I looked into the __init__.py file, I found that there was something called an "invalid marker":
try:
marker = packaging.markers.Marker(text)
return marker.evaluate()
except packaging.markers.InvalidMarker as e:
raise SyntaxError(e) from e
The last version of setuptools to support Python 2.7 was 44.1.1 (Jan 2020). See the changelog.
Upgrade your Python version in order to use setuptools 51.1.1.

error while installing pandas on ubuntu 14

I am trying to install pandas on my ubuntu machine.
I am using this command
sudo pip install pandas
I am getting the following error
Downloading pandas-0.25.1.tar.gz (12.6MB): 12.6MB downloaded
Running setup.py (path:/tmp/pip_build_root/pandas/setup.py) egg_info for package pandas
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/pandas/setup.py", line 21, in <module>
import versioneer
File "versioneer.py", line 1629
print("Adding sample versioneer config to setup.cfg", file=sys.stderr)
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/pandas/setup.py", line 21, in <module>
import versioneer
File "versioneer.py", line 1629
print("Adding sample versioneer config to setup.cfg", file=sys.stderr)
^
SyntaxError: invalid syntax
Can any one please help me with this .
print("Adding sample versioneer config to setup.cfg", file=sys.stderr)
It is a Python 3 syntax.
First install Python 3.
Then run sudo pip3 install pandas or python3 -m pip install pandas.

Unable to install pywinrm without upgrading and breaking pip

When trying to install the module via pip, it says I need to install setuptools 18.5 or higher. So I do a "pip install -U pip" it upgrades my pip version to 10.0.1. Then when I try to install the pywinrm module, it breaks with a Syntax Error.
In fact, it breaks all Pip commands when upgrading to 10.0.1. I have it currently installed with version 7.1.0 and Python 2.6.6
I try this:
pip install pywinrm
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/lib/python2.6/site-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/lib/python2.6/site-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/lib/python2.6/site-packages/pip/_internal/index.py", line 526
{str(c.version) for c in all_candidates},
^รข
SyntaxError: invalid syntax

pip install * have "Syntax error"

A have a problem where try to install module from pip like:
Install packages failed: Error occurred when installing package lxml.
The following command was executed:
packaging_tool.py install --build-dir C:\Users\User\AppData\Local\Temp\pycharm-packaging2629877941665473195.tmp lxml
The error output of the command:
C:\Python32\lib\site-packages\pip\_vendor\pkg_resources\__init__.py:87: UserWarning: Support for Python 3.0-3.2 has been dropped. Future versions will fail here.
warnings.warn(msg)
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1\helpers\packaging_tool.py", line 125, in main
retcode = do_install(pkgs)
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1\helpers\packaging_tool.py", line 56, in do_install
import pip
File "C:\Python32\lib\site-packages\pip\__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Python32\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Python32\lib\site-packages\pip\download.py", line 36, in <module>
from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
File "C:\Python32\lib\site-packages\pip\utils\ui.py", line 15, in <module>
from pip._vendor.progress.bar import Bar, IncrementalBar
File "C:\Python32\lib\site-packages\pip\_vendor\progress\bar.py", line 48
empty_fill = u'\u2219'
^
SyntaxError: invalid syntax
How fix this? I can not install any module or rollback pip.
Python 3.2
Pip 8.1.1
You need to upgrade your Python. Python 3.2 does not support Unicode string literals with the u"..." syntax (the idea was that these are not needed anymore because all string literals are Unicode in Python 3.x). This is why you are getting the error.
In Python 3.3, this feature was restored to make it easier to write code that runs on either Python 2.x or 3.x and clearly PIP is taking advantage of this.
Indeed, the documentation for PIP 8.1.1 mentions that it needs Python 3.3 or later.

Error in running a python script-In pip installation

I am running a python script where it is setting up an environment in unix to run other python scripts. It is trying to install pip and it fails with the following error.
2016-01-25 12:05:50,291 - Checking if pip is installed.
2016-01-25 12:05:50,291 - Pip is not currently installed.
2016-01-25 12:05:50,291 - Installing pip.
Traceback (most recent call last):
File "/tmp/tmpoDUDVr.py", line 19017, in <module>
main()
File "/tmp/tmpoDUDVr.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "/tmp/tmpoDUDVr.py", line 82, in bootstrap
import pip
File "/tmp/tmpm4FmfJ/pip.zip/pip/__init__.py", line 15, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/vcs/subversion.py", line 9, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/index.py", line 29, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/wheel.py", line 39, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/scripts.py", line 14, in <module>
File "/tmp/tmpm4FmfJ/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module>
ImportError: cannot import name HTTPSHandler
Failed to install pip. Error was Command '['python', '/tmp/tmpoDUDVr.py', '- -user', '--upgrade', '--force-reinstall']' returned non-zero exit status 1
I have already installed pip using the command yum -y install python-pip but still it throws this error. I am not able to find this tmp/tmpoDUDVr.py file and everytime I run this tmp file varies.I tried searching hidden files too(ls -a) Could you please shed light? Any thoughts much appreciated..
Try to use "sudo" in this case. PIP was installed the first time as root...

Categories