0

in VScode, I cannot install neither linter nor autopep8 formatter, I keep getting the same error message saying that there's no pip for the environment

I have Python v. 3.8.5 and set the path correctly in VScode settings (/usr/local/bin/python3.8) I have selected Python v. 3.8.5 as my interpreter

The issue might be this:

I have tried several times to install pip like this

apt-get install python3-pip

When I check for pip -V it says

pip 20.2.3 from /home/thomas/.local/lib/python2.7/site-packages/pip (python 2.7)

This message displays even after trying to install the aforementioned pip for python3. So it seems my pip still relates to some old Python v. 2.7, how do I fix this?

My system is Ubuntu 16.04 LS

NB:

If I change my interpreter to Python 3.5, then i can format correctly with autopep8 but this old version does not support formatted strings so I'd much rather have everything working in interpreter 3.8.5

2 Answers2

-1

Usually, the pip for python3 will be available as pip3. Please run pip3 -V or try cat $(which pip3).

Christian
  • 1,341
  • 1
  • 16
  • 35
  • `pip3 -V` gives me what appears to be an error message Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in from pip.utils import get_installed_distributions, get_prog `cat $(which pip3)` renders this result: #!/usr/bin/python3 # GENERATED BY DEBIAN import sys # Run the main entry point, similarly to how setuptools does it, but because # we didn't install the actual entry point from setup.py, don't u Thanks for helping out a beginner – Thomas Bundgård Richardt Sep 15 '20 at 11:33
  • No, I still cannot run linter or formatter in VSCode - `pip3 -V` gives me some kind of weird error message, displayed partially above – Thomas Bundgård Richardt Sep 15 '20 at 11:49
  • but can you install for example `sudo pip3 install autopep8` (a formatter)? – Christian Sep 15 '20 at 11:51
  • No, same error. `sudo pip3 install autopep8` _[sudo] password for thomas: Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in from pip.utils import get_installed_distributions, get_prog File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in from pip.locations import ( File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in from distutils import sysconfig ImportError: cannot import name (...)_ – Thomas Bundgård Richardt Sep 15 '20 at 11:56
  • This seems odd. Maybe try `sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall` (from https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main) – Christian Sep 15 '20 at 11:58
  • Sadly, that command also returns an error: _Traceback (most recent call last): File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.8/runpy.py", line 144, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details __import__(pkg_name) File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in from pip.utils import get_installed_distributions, get_prog (...)_ – Thomas Bundgård Richardt Sep 15 '20 at 12:03
  • It seems to be hard to manually change the python interpreter to 3.8.5 in ubuntu 16, as suggested here .. https://askubuntu.com/questions/1246812/i-cant-install-certain-python-libraries-because-of-importerror-cannot-import – Christian Sep 15 '20 at 12:53
  • how did you install 3.8.5? It seems not quite straight forward https://medium.com/analytics-vidhya/installing-python-3-8-3-66701d3db134 – Christian Sep 15 '20 at 12:55
  • @ThomasBundgårdRichardt can you please answer – Christian Sep 17 '20 at 09:54
-1

Ubuntu uses pip3 for python3 libaries. Install pip3 and try pip3 install library_name

  • Thansk for helping: do you mean try this command `install pip3 /usr/local/bin/python3.8`? that gives an error message ---- Traceback (most recent call last): File "/usr/bin/pip3", line 9, in from pip import main File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in from pip.utils import get_installed_distributions, get_prog File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in from pip.locations import ( File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in from distutils impor ... – Thomas Bundgård Richardt Sep 15 '20 at 11:39
  • This is not completely true, pip and pip3 are respectively for Python 2 and Python 3, under some versions of Ubuntu (and others UNIX-like systems), Python 3 isn't the default Python version hence you need to specify `3` if you want to use it. But you can also bind `/bin/python` to `/bin/python3` (and `/bin/pip` to `/bin/pip3`) if you want python 3 to be the default (use at your own risks) but this has nothing to see with Ubuntu in particular – gogaz Sep 15 '20 at 12:44
  • Hi Gogaz, can you explain a little better what you mean, please? any suggestions on how to get my pip working on python 3.8.5 to use linters and formatters in VScode? (even the debugging doesnt seem to work) – Thomas Bundgård Richardt Sep 15 '20 at 12:49