在virtualenv中返回错误的Django版本 [英] Wrong Django version returned in virtualenv
问题描述
$ virtualenv --no -site-packages django18env
django18env / bin / python2.7中的新的python可执行文件
还在django18env / bin / python
中创建可执行文件安装setuptools,pip ... done。
$ source django18env / bin / activate
(django18env)$
然后我'安装Django 1.8
(django18env)$ sudo pip install django == 1.8
密码:
下载/打包django == 1.8
下载Django-1.8-py2.py3-none-any.whl(6.2MB):6.2MB下载
安装收集的软件包:django
成功安装django
清理...
(django18env)$
一旦运行我有Django安装在django18env / lib / python2.7 / site-packages / django
如果我查看该目录中的__init__.py文件,它显示:
from django.utils.version import get_version
VERSION =(1,8,0,'final',0)
所以它看起来像是在virtualenv目录中安装了正确的版本。但是,如果我使用django-admin --version我得到:
(django18env)$ django-admin版本
1.5.4
我也尝试在虚拟环境中启动python,并以此方式获取django版本:
(django18env)$ python
Python 2.7.8(默认,2014年7月29日,21:50:48 )
[GCC 4.2.1兼容的Apple LLVM 5.1(clang-503.0.40)]在darwin
有关详细信息,请输入help,copyright,credits或license。
>>> import django
>>> django.get_version()
'1.5.4'
>>>
任何想法,为什么在vertualenv中安装1.8时仍然显示为1.5? / p>
我已经在这里阅读了各种其他线程,但无法获取版本指向1.8
任何帮助非常感谢
谢谢
我发现了这个问题。如上所述,Django 1.8正在安装在virtualenv中,但是Python并没有使用它。在vitualenv中,我开始使用Python,然后:
>>> import django
>> ; django .__ file__
这表明Django已经从:
/ usr / local导入/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
当我看着我的时候。 bash_profile有一行:
export PYTHONPATH = $ PYTHONPATH:/usr/local/Cellar/python/2.7.8/Frameworks /Python.framework/Versions/2.7/lib/python2.7/site-packages
不知道如何/当这个在那里,但我评论了,重新启动了shell,我现在得到Django1.8在我的virtualenv和旧的(默认)版本1.5之外的virtualenv。感谢您的帮助和建议
$ b
I'm on a Mac running OS X !0.10 Yosemite. Default versions of Python & Django are 2.7 & 1.5. I'm want to set up a virtualenv that has Django 1.8 so I'm doing the following:
$ virtualenv --no-site-packages django18env
New python executable in django18env/bin/python2.7
Also creating executable in django18env/bin/python
Installing setuptools, pip...done.
$ source django18env/bin/activate
(django18env)$
Then I'm installing Django 1.8
(django18env)$ sudo pip install django==1.8
Password:
Downloading/unpacking django==1.8
Downloading Django-1.8-py2.py3-none-any.whl (6.2MB): 6.2MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
(django18env)$
Once that has run I have Django installed under django18env/lib/python2.7/site-packages/django
If I look at the __init__.py file in that directory it shows:
from django.utils.version import get_version VERSION = (1, 8, 0, 'final', 0)
So it certainly looks like the right version is installed in the virtualenv directory. However, if I use django-admin --version I get:
(django18env)$ django-admin version
1.5.4
I've also tried starting python in the virtual env and getting the django version that way:
(django18env)$ python
Python 2.7.8 (default, Jul 29 2014, 21:50:48)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.5.4'
>>>
Any ideas on why it still seems to be pointing to 1.5 when 1.8 is installed in the vertualenv?
I've read various other threads on here but can't get the version to point to 1.8
Any help much appreciated
Thanks
I found the issue. As I say above, Django 1.8 was being installed in the virtualenv OK but Python wasn't using it. In the vitualenv I started Python and then:
>>>import django
>>>django.__file__
This showed that Django had been imported from: /usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
And when I looked in my .bash_profile there was a line:
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Not sure how/when this got in there but I commented it out, restarted the shell and I now get Django1.8 in my virtualenv and the older (default) version 1.5 outside the virtualenv.
Thanks for the help and suggestions
这篇关于在virtualenv中返回错误的Django版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!