How do I use a conda environment with mod_wsgi?

可紊 提交于 2019-12-03 05:20:24

Your mod_wsgi would need to be compiled against Anaconda Python to start with and not your system Python. In other words you cannot use the system supplied mod_wsgi packages but would need to compile it yourself. Then follow what it says in:

That is, use daemon mode and use the python-home option to WSGIDaemonProcess.

Do note that there have been reports suggesting that Anaconda Python is broken in some way and will not work with systems that want to embed Python. So may not work anyway.

BTW, you cannot use '~' in the path in your WSGI script file anyway with the way you were doing it. It would not be expanded to be the home directory. But then, follow that post and you will not need that.

I'm late to the party on this but I was having the same problem. For what its worth, I didn't have to recompile anything and was able to get this to work by including 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 this points to the site-packages directory.

To add to @dino's answer, you can also install mod_wsgi into your root conda environment:

# Instal `mod_wsgi`
$ pip install mod_wsgi

# Find the full path to installed `mod_wsgi`
$ which mod_wsgi-express

# Install and register the `mod_wsgi` module with Apache
$ sudo /full/path/to/installed/mod_wsgi-express install-module

You can then create conda environments for multiple sites:

# Create 3 conda environments
conda create -n mysite1 python django
conda create -n mysite2 python django
conda create -n mysite3 python django

And set WSGIDaemonProcess in the Apache site configuration file to use the appropriate environment for each site:

# /etc/apache2/sites-enabled/mysite1.conf
WSGIDaemonProcess mysite1 python-path=/path/to/anaconda3/envs/mysite1/lib/python3.5/site-packages

# /etc/apache2/sites-enabled/mysite2.conf
WSGIDaemonProcess mysite2 python-path=/path/to/anaconda3/envs/mysite2/lib/python3.5/site-packages

# /etc/apache2/sites-enabled/mysite3.conf
WSGIDaemonProcess mysite3 python-path=/path/to/anaconda3/envs/mysite3/lib/python3.5/site-packages
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!