0

I installed lighttpd and python-pip3 and then I installed a pip package (in this case, the requests package). Then I tried to use it on a web page (served through CGI) and it did not work; I got an HTTP 500 error.

I wrote a short script to list all the modules that are available to the CGI scripts, and it does not include the pip package.

#!/usr/bin/python
import cgi
import cgitb
import sys
sys.path.insert(0, '/home/user/.local/lib/python3.7/site-packages')

cgitb.enable()  # for troubleshooting
for m in sys.modules:
  print(m)

What am I missing here? How can I make the package available to the CGI? It obviously is available through the command line (i.e. import requests works without an issue when in the command line).

Merik
  • 2,767
  • 6
  • 25
  • 41
  • Try to add `print(sys.executable)`, your script is probably being executed with another python interpreter – FlyingTeller Apr 17 '20 at 06:22
  • As @FlyingTeller suggested: check your lighttpd.conf to see what interpreter is being executed for (presumably) ".py". Is it `/usr/bin/python` or `/usr/bin/python3`? – gstrauss Apr 17 '20 at 09:13
  • The result: `/usr/bin/python3` and when I run `which python3` at the command line, it also gives me the same result. – Merik Apr 17 '20 at 14:14
  • One last thing, I added `print(sys.path)` to my script, and this the output: `['/var/www/html/cgi-bin', '/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']` so it includes the path that contains my desired module (which is `/usr/lib/python3.7/dist-packages`) – Merik Apr 17 '20 at 14:28
  • As it turns out, removing the package and installing it again with sudo fixed the issue. – Merik Apr 17 '20 at 14:36

0 Answers0