简体   繁体   English

您如何告诉django使用哪个python版本?

[英]How do you tell django which python version to use?

The default version of python on centos is 2.6 and I am using a feature in my django app that requires 2.7 . 在centos上python的默认版本是2.6,我在django应用中使用了需要2.7的功能。 Where would I specify which version to use? 我在哪里指定使用哪个版本?

The python path for 2.7 is at /usr/local/bin/python2.7 2.7的python路径位于/usr/local/bin/python2.7

The webserver I am using is apache. 我正在使用的Web服务器是apache。 I have tried a few different things but have not had much luck. 我尝试了几种不同的方法,但是运气不佳。 Any ideas? 有任何想法吗?

If you are using a virtualenv (hint: you should), you can specify the python version when creating the environment: 如果您使用virtualenv (提示:您应该),则可以在创建环境时指定python版本:

virtualenv --python=python2.7 <your_venv_name>

For mod_wsgi , have a look in the apache modules directory. 对于mod_wsgi ,请查看apache modules目录。 I have no experience with centos, but on Debian, in /usr/lib/apache2/modules , you can choose the python version by modifying the mod_wsgi.so symlink (this is on debian oldstable): 我没有使用centos的经验,但是在Debian上的/usr/lib/apache2/modules ,可以通过修改mod_wsgi.so symlink(在debian oldstable上)来选择python版本:

lrwxrwxrwx 1 root root     15 Feb 10  2011 mod_wsgi.so -> mod_wsgi.so-2.5
-rw-r--r-- 1 root root 151648 Sep 26  2010 mod_wsgi.so-2.5
-rw-r--r-- 1 root root 151680 Sep 26  2010 mod_wsgi.so-2.6

(For reference: for python3, you need to install a separate package, libapache2-mod-wsgi-py3 ) (作为参考:对于python3,您需要安装一个单独的软件包libapache2-mod-wsgi-py3

I imagine centos has something similar. 我想象centos有类似的东西。 If there isn't, you need to either find a mod_wsgi package built against python 2.7, or rebuild mod_wsgi from source against the right python version. 如果没有,则需要找到针对python 2.7构建的mod_wsgi软件包,或者针对正确的python版本从源代码重建mod_wsgi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在多个操作系统中手动告诉Python在脚本本身中使用哪个版本? - How do you manually tell Python which version to use in the script itself, across multiple operating systems? 我如何告诉 cmake 使用哪个版本的 python? - How do I tell cmake which version of python to use? 如何指定要在Django 1.1.1中使用的python可执行文件? - how do you specify which python executable to use in Django 1.1.1? Python 3 - 你如何告诉 pipenv 使用 python 3 而不是 python 2? - Python 3 - How do you tell pipenv to use python 3 and not python 2? 如何告诉 Python 脚本使用特定版本 - How do I tell a Python script to use a particular version 如何判断 CLI 使用的是哪个版本的 python? - How to tell which version of python a CLI uses? 你如何判断 VS Code 使用的 Python 格式化程序的版本? - How do you tell the version of the Python formatter being used by VS Code? 如何告诉python使用哪个版本的libmysqlclient.so? - How can I tell python which version of libmysqlclient.so to use? 如何告诉控制台要使用哪个python安装 - How to tell the console which python to use for installation 如何告诉 Flask (.flaskenv) 使用哪个 python - How to tell Flask (.flaskenv) which python to use
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM