简体   繁体   中英

Using Anaconda python with mod_wsgi

I'm trying to set up my Apache server to use Anaconda python instead of the system python when using mod_wsgi.

Here is my Apache config file:

 LoadModule wsgi_module modules/mod_wsgi.so
 WSGIPythonHome /opt/anaconda/bin
 WSGIPythonPath /opt/anaconda/bin:/opt/anaconda/pkgs

As soon as I start the server, my error log is flooded with

ImportError: No module named site
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]

mod_wsgi is version 4.4.12 and compiled with the same version of python as my anaconda installation (2.7.10).

What am I doing wrong? How do I set up my Apache config file to run python from the non-default location?

It seems like your Python path is set incorrectly. Go into your Anaconda python and type in:

import site
site

The directory of your site module should be displayed. It should be something like: python_path/lib/site.pyc

Change your Apache configuration to:

WSGIPythonPath python_path:python_path/lib/site-packages

where python_path was the thing you found above when importing site .

I'm late to the party on this but I was having the same problem. To clarify @Ringil's solution, I included something like this in my VirtualHost configuration using the system-installed mod_wsgi:

WSGIDaemonProcess mysite python-path=/path/to/anaconda2/lib/python2.7/site-packages

Note that, as @Ringil points out, the site-packages directory needs to be on the PYTHONPATH .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM