Markus
Markus

Reputation: 624

Cannot import python3-requests, though it is installed

On Debian 10, when I try to import requests, I get:

$ python3 -c 'import requests'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'

However, requests module is installed:

$ dpkg -L python3-requests
/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/requests
/usr/lib/python3/dist-packages/requests/__init__.py
...

Also, /usr/lib/python3/dist-packages is in path:

$ python3 -c 'import sys;print(sys.path)'
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.7/dist-packages']

I found out, that, if I pip3-install requests as root, I can import requests.

But why can python not import the (debian) packages from python3-requests?

Btw, I am having the same problem with package python3-gi where I can not import gi.

I think something is very broken...

Upvotes: 0

Views: 363

Answers (1)

Markus
Markus

Reputation: 624

I found the "solution"... Though dpkg -L suggests an installation in /usr/lib/python3/dist-packages/requests there is no such file:

$ ls /usr/lib/python3/dist-packages/requests
ls: Zugriff auf '/usr/lib/python3/dist-packages/requests' nicht möglich: Datei oder Verzeichnis nicht gefunden

I had to do

apt-get --reinstall install python3-requests

If --reinstall is left out, it won't work. Strange.

Upvotes: 1

Related Questions