我在Mac上运行OS X!0.10 Yosemite。 Python&的默认版本Django是2.7& 1.5。我想建立一个拥有Django 1.8的virtualenv,所以我正在做以下事情:
$ 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)$
然后我正在安装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)$
一旦运行,我在django18env / lib / python2.7 / site-packages / django下安装了Django
如果我查看该目录中的__init__.py文件,它会显示:
来自django.utils.version导入get_version VERSION =(1,8,8,'final',0)
所以看起来肯定在virtualenv目录中安装了正确的版本。但是,如果我使用django-admin --version,我会得到:
(django18env)$ django-admin version
1.5.4
我也尝试在虚拟环境中启动python并以这种方式获取django版本:
(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'
>>>
在vertualenv中安装1.8时,为什么它似乎仍然指向1.5的任何想法?
我在这里阅读了各种其他线程,但无法将版本指向1.8
任何帮助非常感谢
由于
答案 0 :(得分:0)
不要在virtualenv上使用sudo。 vitualenv的重点是,安装软件不是系统范围的,但确实适用于该环境。但无论是在virtualenv内部还是在其外部,如果您使用sudo,它都会在全局范围内为您的系统安装软件。
ziya@ziya:~/Desktop/coursera/python/lorem$ virtualenv ipsum
New python executable in ipsum/bin/python2.6
Also creating executable in ipsum/bin/python
Installing setuptools, pip...done.
#created a virtualenv
ziya@ziya:~/Desktop/coursera/python/lorem$ cd ipsum/
ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ . bin/activate
# will now install package with sudo
(ipsum)ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ sudo pip install sudokulib # i don't know what it is, just installing.
[sudo] password for ziya:
.....
Collecting sudokulib
/usr/local/lib/python2.7/dist-packages # attention to this path!
...
Successfully installed sudokulib-0.6a0
(ipsum)ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib # import the newly installed module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sudokulib
>>> exit()
(ipsum)ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ deactivate
#deactivating virtualenv and starting default python
ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib
>>> sudokulib.__version__
'0.6a' #here it is!
>>> exit()
ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ . bin/activate
(ipsum)ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ pip install sudokulib #now installing the same module without sudo
Collecting sudokulib
Downloading sudokulib-0.6a.tar.gz
/home/ziya/Desktop/coursera/python/lorem/ipsum/lib/python2.6/site-packages
....
Successfully installed sudokulib-0.6a0
(ipsum)ziya@ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib
>>> sudokulib.__version__
'0.6a' #seems ok now :)
>>>
答案 1 :(得分:0)
我发现了这个问题。正如我上面所说,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,现在我的virtualenv中的Django1.8和virtualenv之外的旧版(默认版)1.5。
感谢您的帮助和建议