Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get-pip.py returns SyntaxError: invalid syntax [duplicate]

I installed pip from this command

curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py

and when I did sudo python2 get-pip.py

Traceback (most recent call last):
  File "get-pip.py", line 24226, in <module>
    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/tmpf3jeCG/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

It was working fine a few weeks back and then suddenly it has stopped working. I really need to know what I have done wrong? Is there any other way I can do it? I'm using Atlassian Bitbucket which has Java8 image. I also need pip installed since I can not have more than one image. I'm downloading it locally using the above command and making pip work. Is there anyother way I can use it to make it work?

like image 833
Ashutosh Soni Avatar asked Jan 28 '21 07:01

Ashutosh Soni


People also ask

How do I fix pip invalid syntax?

If you get a "SyntaxError: invalid syntax" when trying to install a module using pip , make sure to run the command from your shell, e.g. bash or PowerShell, and not by running a Python file that contains the pip install your_module command.

Why is pip install invalid syntax?

The python pip invalid syntax error is occurring because pip is run from the command line, not the Python interpreter. It is a program that installs modules, so you can use them from Python. Once you have installed the module, then you can open the Python shell and do import selenium.

How do I fix invalid syntax?

Defining and Calling Functions You can clear up this invalid syntax in Python by switching out the semicolon for a colon. Here, once again, the error message is very helpful in telling you exactly what is wrong with the line.


1 Answers

The support for Python 2.7 is deprecated on newer versions of pip, hence the reason why you're noticing this error here.

In order for you to maintain the sanity with Python 2.7 and pip, either maintain yourself to lower version of pip using the pip installer itself

pip install --upgrade pip==20.3

or make use of the Python 2.7 specific version of get-pip.py

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
like image 157
DhakkanCoder Avatar answered Oct 12 '22 08:10

DhakkanCoder