2

I'm on Linux Mint 18.3 Sylvia. I have an issue with pip and python3, and no other issues helped me actually. dsds Everything work when I do python -m pip --version pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7) But whenusing python3 doing python3 -m pip --version

I get the following message

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 "/home/max/.local/lib/python3.5/site-packages/pip/__main__.py", line 21, in <module> from pip._internal.cli.main import main as _main File "/home/max/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60 sys.stderr.write(f"ERROR: {exc}") ^ SyntaxError: invalid syntax

Any ideas to how solve this ? Thanks you!

edit: python command is Python 2.7.12

edit2: I originally wanted to install matplotlib as described here. By using the command python -m pip install -U pip as told in the installation process. This is probably the issue, as now it show the error for both python and python3 command...

LittlePanic404
  • 130
  • 1
  • 1
  • 7
  • 1
    did you try to type only this one```pip --version```? – bilakos Jan 24 '21 at 00:00
  • it gives me same error as described in my post :( – LittlePanic404 Jan 24 '21 at 00:16
  • 1
    The stack trace is informative, but I'm afraid it doesn't help me figure out how to fix it. `sys.stderr.write(f"ERROR: {exc}")` is a SyntaxError on Python 3.5 (which is seems like you have). the f-string syntax is only legal in Python 3.6+. It's unclear, however, why that code would be running in a pip that's installed on python 3.5.... – Adam Smith Jan 24 '21 at 01:35
  • See https://stackoverflow.com/a/65871131/7976758 – phd Jan 24 '21 at 13:43

3 Answers3

4

Here's what I would try.

$ wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py

That should run the latest get-pip and install it in your python3 installation. As mentioned in my comment on your question, it looks like the version of pip that is installed is incompatible with your version of Python (it's running 3.6+ code in 3.5) so maybe installing fresh will make life better.

111
  • 1,788
  • 1
  • 23
  • 38
Adam Smith
  • 52,157
  • 12
  • 73
  • 112
1

You must at first remove all pip* files :

sudo rm -rf /usr/local/lib/python3.x/dist-packages/pip*

Then reinstall pip :

sudo apt install python3.x-pip
0

When you are writing "python" on command windows Which version it shows ? Having python 2 and 3 simoltaneously should not make problem for you But sometimes it is conflicting because of environmental variable or path.

Ozgur
  • 76
  • 4