I have a PHP script that call a python script (someone else I can't edit). This work fine on CLI but once I run it as CGI it fails with the error "bzr: ERROR: Couldn't import bzrlib and dependencies."
I guessed it has anything to do with PYTHONPATH so I echo it out and found that it was empty when in apache environment.
I try setting it in my '.htaccess' (I am on Dreamhost so I can't set httpd.conf) as:
SetEnv PYTHONPATH "/home/nawaman/lib/python"
It still does not work.
What can I do about this? Thanks in advance for any help.
Practical Data Science using PythonTo call a Python file from within a PHP file, you need to call it using the shell_exec function.
It is used to set the path for the user-defined modules so that it can be directly imported into a Python program. It is also responsible for handling the default search path for Python Modules. The PYTHONPATH variable holds a string with the name of various directories that need to be added to the sys.
The PYTHONPATH environment variable is used by Python to specify a list of directories that modules can be imported from on Windows. When running, you can inspect the sys. path variable to see which directories will be searched when you import something.
As far as I know, Apache's environment variables don't correlate with the system ones.
Try setting PYTHONPATH
using PHP's putenv()
Alternatively, I don't know much about Python, but it seems to be possible to set the path inside a Python script using sys.path
maybe that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With