Django Apache and Virtualenv ImportError: No module named site

后端 未结 4 1118
野的像风
野的像风 2020-12-18 04:05

The error from apache after a 504 page

[info] mod_wsgi (pid=): Python home /var/venv/mybox.
[info] mod_wsgi (pid=): Initializing Python.
ImportError: No mod         


        
4条回答
  •  鱼传尺愫
    2020-12-18 04:34

    The documentation for using virtual environments with mod_wsgi can be found at:

    • http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html

    Most important in your case is the section:

    • Virtual Environment and Python Version

    In that section it states:

    When using a Python virtual environment with mod_wsgi, it is very important that it has been created using the same Python installation that mod_wsgi was originally compiled for. It is not possible to use a Python virtual environment to force mod_wsgi to use a different Python version, or even a different Python installation.

    You cannot for example force mod_wsgi to use a Python virtual environment created using Python 3.5 when mod_wsgi was originally compiled for Python 2.7. This is because the Python library for the Python installation it was originally compiled against is linked directly into the mod_wsgi module.

    So most likely what is happening is that mod_wsgi is compiled for Python 2.6. You cannot in this case force it to use a Python virtual environment created from Python 2.7. When you do this, you will get the error you see about site module being missing.

    You will need to uninstall that mod_wsgi from system packages and install mod_wsgi from source code, compiling it against Python 2.7. The easiest way to do this might be to use the pip install method as described in:

    • https://pypi.python.org/pypi/mod_wsgi

    Run pip install to install it in your virtual environment and then follow instructions in section 'Connecting into Apache installation' about configuring Apache to use it.

提交回复
热议问题