我在Ubuntu 12.04 LTS上设置一个Django服务器,我在使用正确版本的python安装mod-wsgi时遇到问题.我用python 3.3在本地构建了我的站点,Ubuntu 12.04与python 3.2捆绑在一起.我想我可以,但宁愿不只是使用3.2而不是3.3,所以我在3.2旁边安装了python 3.3.除了mod-wsgi之外,我为python 3.3安装了所有东西.
在运行python3.3的本地机器上安装libapache2-mod-wsgi-py3并sudo apt-get install libapache2-mod-wsgi-py3
安装python3.3.但是在Ubuntu服务器上,运行相同的代码会为python3.2安装它,以便Web服务器运行3.2并且找不到django.
有没有办法禁用python3.2,或指向脚本为python 3.3安装它?
编辑:经过深入研究,python3.2没有与ubuntu捆绑在一起,而是与libapache2-mod-wsgi-py3一起安装
我发现了如何在Ubuntu 12.04 LTS上构建与Python 3.3.5一起使用的mod_wsgi.
诀窍是能够安装python3.3-dev软件包,Ubuntu 12.04 LTS("精确")不支持.有一个由Felix Krull维护的第三方存储库,它可以提供新的和新的Python构建(Kudos to Felix!):
https://launchpad.net/~fkrull/+archive/deadsnakes
要安装Felix的存储库:
sudo add-apt-repository ppa:fkrull/deadsnakes sudo apt-get update
在开始构建mod_wsgi之前,我们需要apache2-dev包...
sudo apt-get install apache2-dev
...并获取python3.3-dev软件包(这实际上也安装了python3.3!)
sudo apt-get install python3.3-dev
下载mod_wsgi代码并通过提供新安装的Python库和头文件(/usr/bin/python3.3)的路径来构建它.可以在以下位置找到带有最新mod_wsgi版本的下载链接:
https://github.com/GrahamDumpleton/mod_wsgi/releases
cd /usr/local/src sudo wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/modwsgi/mod_wsgi-3.4.tar.gz sudo tar -zxvf mod_wsgi-3.4.tar.gz cd mod_wsgi-3.4/ sudo ./configure --with-python=/usr/bin/python3.3 sudo make sudo make install
mod_wsgi.so放在/ usr/lib/apache2/modules /中
可选步骤: 由于它们丢失了,我手动(重新)创建了/ etc/apache2/mods-available中的wsgi.conf和wsgi.load文件(尽管我没有设置任何特定选项).
wsgi.conf:
<IfModule mod_wsgi.c> # See http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives #WSGISocketPrefix: Configure directory to use for daemon sockets. #WSGISocketPrefix /var/run/apache2/wsgi #WSGIPythonOptimize: Enables basic Python optimisation features. #WSGIPythonOptimize 0 #WSGIPythonPath: Additional directories to search for Python modules, # overriding the PYTHONPATH environment variable. #WSGIPythonPath directory|directory-1:directory-2:... #WSGIPythonEggs: Directory to use for Python eggs cache. #WSGIPythonEggs directory #WSGIRestrictEmbedded: Enable restrictions on use of embedded mode. #WSGIRestrictEmbedded On|Off #WSGIRestrictStdin: Enable restrictions on use of STDIN. #WSGIRestrictStdout: Enable restrictions on use of STDOUT. #WSGIRestrictSignal: Enable restrictions on use of signal(). #WSGIRestrictStdin On #WSGIRestrictStdout On #WSGIRestrictSignal On #WSGIAcceptMutex: Specify type of accept mutex used by daemon processes. #WSGIAcceptMutex default #WSGIImportScript: Specify a script file to be loaded on process start. #WSGIImportScript process-group=name application-group=name #WSGILazyInitialization: Enable/disable lazy initialisation of Python. #WSGILazyInitialization On|Off </IfModule>
wsgi.load:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
最后,可以通过创建如下符号链接来启用mod_wsgi:
cd /etc/apache2/mods-enabled sudo ln -s ../mods-available/wsgi.conf wsgi.conf sudo ln -s ../mods-available/wsgi.load wsgi.load
让我知道这是否也适合你!