How do I use a conda environment with mod_wsgi?

Nathaniel

My first post, and I'm new to both Python and Apache, so please go easy on me. I have a Python web application in a conda environment that serves up content just fine using Flask. Now I need to serve everything with Apache instead of Flask. I can get Apache to run Python with mod_wsgi, but only with virtualenv. I tried installing virtualenv with Anaconda, but I received a warning that such a setup is unsupported and not recommended. So my question is this:

How do I set up Apache to run my application in a conda environment?

Here, there's a section on working with virtual environments, and it says I need to enter a line into my wsgi file showing where to find activate_this.py. A virtualenv virtual environment has activate_this.py, but a conda environment does not. It seems that without the right instructions for activating the virtual environment, I'm just getting error 500 in my browser and "Import error: no module named flask" in my httpd error_log.

This is in my httpd.conf file:

<VirtualHost *:80>
     DocumentRoot /var/www
     WSGIScriptAlias / var/www/tsm.wsgi
     <Directory /var/www/tsm>
     Order allow,deny
     Allow from all
     </Directory>
</VirtualHost>

And here is tsm.wsgi:

import sys
import site
site.addsitedir('~/.conda/envs/tsm/lib/python2.7/site-packages')
sys.path.insert(0, '/var/www/tsm/server/time_series_machine')
sys.stdout = sys.stderr
from app import app as application

Any ideas? Thanks for any help you can provide.

dino

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I prevent Conda from activating the base environment by default?

From Java

How can I rename a conda environment?

From Java

How do I use Docker environment variable in ENTRYPOINT array?

From Java

How do I keep track of pip-installed packages in an Anaconda (Conda) environment?

From Java

Use Conda environment in pycharm

From Java

How to use Jupyter notebooks in a conda environment?

From Dev

How do I clone a conda environment from one python release to another?

From Dev

How do I use a user environment variable in gradle.properites

From Dev

How can I use conda to install pydot?

From Dev

How do I safely get the user's real IP address in Flask (using mod_wsgi)?

From Dev

Where do I store my django project code when using apache and mod_wsgi?

From Dev

How do I use a localized PostBuildEvent in an environment with multiple collaborators?

From Dev

How to use uuid lib with mod_wsgi?

From Dev

How can I use Conda to install MySQLdb?

From Dev

How do I pip install packages in a conda environment.yml file?

From Dev

Anaconda - I have set up an environment, how do I use it?

From Dev

How do I find the name of the conda environment in which my code is running?

From Dev

How can I use conda to install pydotplus

From Dev

Does django already come with a wsgi application file, or do I need to create one? How to setup apache and mod_wsgi with django?

From Dev

How do you install mod_wsgi?

From Dev

How can I rename a conda environment?

From Dev

Use Conda environment in pycharm

From Dev

How to use Jupyter notebooks in a conda environment?

From Dev

How do I set optional arguments in the conda environment.yml file?

From Dev

How do I use a temporary environment variable in a bash for loop?

From Dev

How do I use helpers with Dust.js on a local environment?

From Dev

How do I install libsvm in a conda environment so that I can import svm in anaconda?

From Dev

Is mod_WSGI replacing what apache is doing and how I can make wsgi work at a specific path only

From Dev

How do you get 'sudo' privilege for a program in a conda virtual environment?

Related Related

  1. 1

    How do I prevent Conda from activating the base environment by default?

  2. 2

    How can I rename a conda environment?

  3. 3

    How do I use Docker environment variable in ENTRYPOINT array?

  4. 4

    How do I keep track of pip-installed packages in an Anaconda (Conda) environment?

  5. 5

    Use Conda environment in pycharm

  6. 6

    How to use Jupyter notebooks in a conda environment?

  7. 7

    How do I clone a conda environment from one python release to another?

  8. 8

    How do I use a user environment variable in gradle.properites

  9. 9

    How can I use conda to install pydot?

  10. 10

    How do I safely get the user's real IP address in Flask (using mod_wsgi)?

  11. 11

    Where do I store my django project code when using apache and mod_wsgi?

  12. 12

    How do I use a localized PostBuildEvent in an environment with multiple collaborators?

  13. 13

    How to use uuid lib with mod_wsgi?

  14. 14

    How can I use Conda to install MySQLdb?

  15. 15

    How do I pip install packages in a conda environment.yml file?

  16. 16

    Anaconda - I have set up an environment, how do I use it?

  17. 17

    How do I find the name of the conda environment in which my code is running?

  18. 18

    How can I use conda to install pydotplus

  19. 19

    Does django already come with a wsgi application file, or do I need to create one? How to setup apache and mod_wsgi with django?

  20. 20

    How do you install mod_wsgi?

  21. 21

    How can I rename a conda environment?

  22. 22

    Use Conda environment in pycharm

  23. 23

    How to use Jupyter notebooks in a conda environment?

  24. 24

    How do I set optional arguments in the conda environment.yml file?

  25. 25

    How do I use a temporary environment variable in a bash for loop?

  26. 26

    How do I use helpers with Dust.js on a local environment?

  27. 27

    How do I install libsvm in a conda environment so that I can import svm in anaconda?

  28. 28

    Is mod_WSGI replacing what apache is doing and how I can make wsgi work at a specific path only

  29. 29

    How do you get 'sudo' privilege for a program in a conda virtual environment?

HotTag

Archive