0

The situation is like this:

  1. in my httpd.conf, I have

    SetEnv PYTHONPATH /Users/<MY_NAME_>/PATH_TO/py3
    
  2. my Python script in a browser runs, prints something like a header, and then I print from it the environment like

    [(x, os.environ [x]) for x in os.environ if "PY" in x]
    

I can see this path to my Python stuff printed. It is in the Apache environment.

However the next line in my script, which is:

from my_module import * # module **is** in the directory which is in PYTHONPATH 

gives an error:

ModuleNotFoundError: No module named '....'

This doesn't make sense to me.

This is under macOS 13.6.3 Ventura.

4
  • Is this smth. about permissions?...... Commented Oct 25 at 19:38
  • But then it should give a different error message: CannotRunModule instead of ModuleNotFoundError? Right? Our World is so confusing. Commented Oct 25 at 19:40
  • can you import your module like that normally? PYTHONPATH=foo python3 -c 'from my_module import *' (and did you mean to respond to yourself?) Commented Oct 25 at 20:48
  • >> can you import your module like that normally? -- Yes. Commented Oct 27 at 10:32

1 Answer 1

0

Set the Python path inside Apache’s WSGI configuration, e.g.:

WSGIPythonPath /Users/<MY_NAME_>/PATH_TO/py3

or in your <VirtualHost>:

WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess myapp python-path=/Users/<MY_NAME_>/PATH_TO/py3
WSGIProcessGroup myapp
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you but I don't use WSGI. I use Options +ExecCGI AddHandler cgi-script .py under <Directory "my_document_root"> and also LoadModule cgi_module libexec/apache2/mod_cgi.so
Cannot format my comment properly; sorry.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.