Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip install on Python 2 fails with SyntaxError: sys.stderr.write(f"ERROR: {exc}") #9500

Closed
frimpz opened this issue Jan 23, 2021 · 12 comments
Closed
Labels
resolution: no action When the resolution is to not do anything

Comments

@frimpz
Copy link

frimpz commented Jan 23, 2021

Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in
load_entry_point('pip==21.0', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 339, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 2470, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 2184, in load
['name'])
File "/usr/local/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")

@jaszhang
Copy link

Got the same issue

@frimpz
Copy link
Author

frimpz commented Jan 23, 2021

Yh but pip install pip==20.3.3 does not give this problem.

I guess the problem is with the new release v21.0, which is on (2021-01-23).

@miketimofeev
Copy link

Same here with python 3.5.2. Even pip3 --version gives the error

Traceback (most recent call last):
  File "/usr/bin/pip3", line 11, in <module>
    sys.exit(main())
  File "/home/vsts/.local/lib/python3.5/site-packages/pip/__init__.py", line 16, in main
    from pip._internal.utils.entrypoints import _wrapper
  File "/home/vsts/.local/lib/python3.5/site-packages/pip/_internal/utils/entrypoints.py", line 3, in <module>
    from pip._internal.cli.main import main
  File "/home/vsts/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

@cainmagi
Copy link

cainmagi commented Jan 24, 2021

It is annoying that the new str format f"" only supports python>=3.6. I recommend users who are using python 3.5 to use the following script instead:
https://bootstrap.pypa.io/3.4/get-pip.py
It only supports pip19.1.1.

For users who are using python 2.7, this is a better solution:
https://bootstrap.pypa.io/2.7/get-pip.py
It supports pip20.3.4.

I am not sure whether the latter version supports python3.5. I think it supposes to work.


Confirmed, currently
https://bootstrap.pypa.io/2.7/get-pip.py
works on python3.5.

Edited on 1/14/2021

@pradyunsg
Copy link
Member

pradyunsg commented Jan 24, 2021

Users of aws-quickstart: please see #9501.

pip 21.0 dropped support for Python 2.7 and Python 3.5. We also dropped support for the same in get-pip.py. As @cainmagi noted, users of Python 2 are expected to use https://bootstrap.pypa.io/2.7/get-pip.py going forward. There's an open issue for adding a corresponding Python 3.5 compatible script too, which would basically be the same as the 2.7 compatible one: pypa/get-pip#83

@pradyunsg pradyunsg changed the title Pip install error pip install on Python 2 fails with SyntaxError: sys.stderr.write(f"ERROR: {exc}") Jan 24, 2021
@pradyunsg pradyunsg added the resolution: no action When the resolution is to not do anything label Jan 24, 2021
mcab added a commit to Clever/ci-scripts that referenced this issue Jan 24, 2021
On our CI images, the `python` executable is Python 2.7.

pip 21.0 dropped support for Python 2.7 (pypa/pip#9500)
and says to use a different URL to still retain that support. In order to install AWS CLI
from pip, we need to have a compatible version of pip.
@crazymind1337
Copy link

Same here on Ubuntu 16.04 with pyenv:

./pip3 --version
Traceback (most recent call last):
  File "./pip3", line 7, in <module>
    from pip._internal.cli.main import main
  File "/opt/check-docker/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")

@MauriceHendrix
Copy link

MauriceHendrix commented Jan 25, 2021

I noticed the same issue with python 3.5. It works fine when upgrading the system pip, but if I try it in a virtual environment it tries to install pip 21.0 (whih requires python >= 3.6).

-- Found PythonInterp: /usr/bin/python3.5 (found suitable version "3.5.2", minimum required is "3.5") 
-- Updating pip setuptools and wheel
Collecting pip
  Downloading https://files.pythonhosted.org/packages/de/47/58b9f3e6f611dfd17fb8bd9ed3e6f93b7ee662fb85bdfee3565e8979ddf7/pip-21.0-py3-none-any.whl (1.5MB)
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/f7/30/f963996d7efea5a336455a3c727711469280c318e2711e295007dea04d7e/setuptools-52.0.0-py3-none-any.whl (784kB)
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/65/63/39d04c74222770ed1589c0eaba06c05891801219272420b40311cd60c880/wheel-0.36.2-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
  Found existing installation: pip 8.1.1
    Uninstalling pip-8.1.1:
      Successfully uninstalled pip-8.1.1
  Found existing installation: setuptools 20.7.0
    Uninstalling setuptools-20.7.0:
      Successfully uninstalled setuptools-20.7.0
Successfully installed pip-21.0 setuptools-52.0.0 wheel-0.36.2
-- Installing chaste_codegen
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/var/lib/buildbot/slaves/slave/Continuous_Clang_Tidy/build/Debug_develop/codegen_python3_venv/lib/python3.5/site-packages/pip/__main__.py", line 21, in <module>
    from pip._internal.cli.main import main as _main
  File "/var/lib/buildbot/slaves/slave/Continuous_Clang_Tidy/build/Debug_develop/codegen_python3_venv/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

If I specify a specific version it works but I get a message about a newer pip being available:

Successfully installed pip-20.3.4
You are using pip version 20.3.4, however version 21.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
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.

@adamdavis40208
Copy link

a python version check and a friendly error message is much preferred to

  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")

Just an FYI, it took us a few minutes longer to debug than a helpful error message

@MarkoPetteri
Copy link

I used the suggested pip version for 2.7 but it still didn't work. So what should I do? Install a newer version of Python or try another pip? I'm very much a noob here so please go easy on me if I'm missing something painfully obvious here.

Traceback (most recent call last):
File "get-pip.py", line 24226, in
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpn1iu0Q/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax

@adamdavis40208
Copy link

adamdavis40208 commented Jan 28, 2021

marko, they've removed support for python 2.7. Pin to a previous version. Or upgrade to python 3.6

On the get-pip side of the world, this is the best link i've ran into: https://utcc.utoronto.ca/~cks/space/blog/python/Python2TimeToGetPipAndMore

You "should" have a version of pip already, so instead of get-pip do pip install --upgrade pip==20.3 or so

edit: from a recently opened pr (pypa/get-pip#87) Please use https://bootstrap.pypa.io/2.7/get-pip.py

@MarkoPetteri

This comment has been minimized.

@pradyunsg
Copy link
Member

To everyone hitting this: Please use https://bootstrap.pypa.io/2.7/get-pip.py.

@pypa pypa locked as resolved and limited conversation to collaborators Jan 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolution: no action When the resolution is to not do anything
Projects
None yet
Development

No branches or pull requests

9 participants