1

I've been trying to use VS Code's python debugger on Linux (mint), which uses debugpy and it keeps giving the error "No module named '_ctypes'". Installing libffi-dev didn't fix it as suggested elsewhere on SO and neither did reinstalling python and python3; so, I tried installing debugpy through pip:

pip install debugpy

Which installs with no issues. However, both python and python3 commands cannot find the module despite the fact that the module is installed (which I can see when I enter pip list)

python -m debugpy
/usr/bin/python: No module named debugpy
python3 -m debugpy
/usr/local/bin/python3: No module named debugpy

So after trying to reinstall pip multiple times, I tried installing through the pip module

python -m pip install debugpy
/usr/bin/python: No module named pip
python3 -m pip install debugpy
/usr/local/bin/python3: No module named pip

So it seems my pip module is also missing too. It may have something to do with my multiple installations of python3 as it seems that there is one in /bin and in /usr/local/bin and the local installation is the one that gets called with the python3 command according to which python3. This leads to multiple questions:

  1. Should the pip module be installed in python, and if so how do I install it again?
  2. How can I get the pip command to actually install the modules into python?
  3. How can I ensure that there is only one python3 installation in Linux (mint/ubuntu)?

Thank-you. If it helps answer the question, I do not seem to have a PYTHONPATH variable.

  • Does this answer your question? [Dealing with multiple Python versions and PIP?](https://stackoverflow.com/questions/2812520/dealing-with-multiple-python-versions-and-pip) – quamrana Aug 06 '21 at 09:53

4 Answers4

0

i had same issue but it can be fixed by two methods.

  1. reinstall pip for the latest python version you use.

2.use the version default python version which came with your python install

  • I've already tried reinstalling pip multiple times. I also don't know which python version actually is the default version. The python3 command may or may not be pointing to the original. – Hakunamawatta Aug 06 '21 at 10:13
0

On ubuntu you can try to do sudo apt install python-pip python3-pip. Also there a couple ways you can try what PIP's documentation recommends: Installation

You can try checking sudo update-alternatives --config python maybe you'll see several python installations there.

Also you can check pip contents to find out what python binary it uses:

$ which pip
/usr/local/bin/pip
$ cat /usr/local/bin/pip
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

#!/usr/bin/python3

  • I've tried "sudo apt install python3-pip" but that doesn't fix the issue. "python-pip" doesn't exist. Neither of the methods suggested on the guide work as for some reason it believe zlib is not installed even after running "sudo apt install zlib1g" which should be the ubuntu version of zlib. But yes, the version that pip uses seems to not be the one the python3 command points to. – Hakunamawatta Aug 06 '21 at 10:18
0

It's difficult to narrow down a solution for apparently you have done a mess... To start, do yourself a favor:

  • Don't touch your System's Python!

Again, it is difficult for me to understand what is the current state of your Python scene... just promise me you'll fix your System's Python 2/3 (i.e, guarantee pip 2/3 there, using your system's package manager (apt, yum, etc)).

Then, start using some virtual environment manager, nowadays we have Pipenv (https://pipenv.pypa.io/), which can be a bit cumbersome at first but -- trust me -- in ~1 hour you'll love it.

Conda (https://docs.conda.io/) is also a great env manager (or the classics (pyenv, venv, etc...)).

...Just pick one and leave your OS' Python alone. You'll see that your issues will not only get simpler to diagnose but you'll also be able to sleep in peace ;)

Brandt
  • 5,058
  • 3
  • 28
  • 46
  • Dang. Seems like pipenv module installations won't work because zlib1g isn't recognised as zlib :/ – Hakunamawatta Aug 06 '21 at 10:31
  • There's no zlib python module as far as pip can tell either. – Hakunamawatta Aug 06 '21 at 10:43
  • All questions relating to the missing zlib library is due to compiling python from source, which I am not doing. I don't think there's any reason for me to be missing this library unless installing python again from the package manager somehow broke it. – Hakunamawatta Aug 06 '21 at 11:16
0

I tried installing it with pip and it has worked for me. The problem you might have is that it is not installed in the correct version of python (e.g it installs for python2 instead of python3 or it installs in python3.8 instead of python3.9).

What you can do to avoid this problem is to create a virtual environment, as is explained in this link: https://docs.python.org/3/tutorial/venv.html. If you do that, remember to change the interpreter path in VSCode. At the bottom left of the screen there should be the python version that you are using. If you click on it you see different interpreter versions that you can use. Select 'Enter interpreter path' and manually choose the directory where you have saved the new python virtual environment.

Unnamed
  • 3
  • 4
  • 1
    Python seems to be missing a module called zlib that's required for the virtual environment to work but there doesn't seem to be a way to install it. Pip can't seem to find such a module and installing the program zlib1g doesn't help either. – Hakunamawatta Aug 06 '21 at 10:42
  • Well, sorry this was not helpful – Unnamed Aug 07 '21 at 11:04