[英]PIP cannot install Django inside VIrtualenv
(myenv) wanjila@wanjila:~/Desktop/Python-Area/projects/Djangular$ pip freeze
djangorestframework==3.7.3
pkg-resources==0.0.0
(myenv) wanjila@wanjila:~/Desktop/Python-Area/projects/Djangular$ pip install django
Collecting django
Using cached Django-2.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-qAnv7G/django/setup.py", line 32, in <module>
version = __import__('django').get_version()
File "django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "django/utils/version.py", line 61, in <module>
@functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
------------------------------------
I keep getting that error whenever i try to pip install django while inside my virtualenv. 每当我尝试在我的virtualenv内部安装django时,我都会收到这个错误。 How can i fix this.
我怎样才能解决这个问题。
作为wim答案的替代方案,如果由于某种原因无法升级Python版本,可以安装仍然与Python 2.7兼容的Django 1.11:
pip install 'django<2.0'
Make sure your Python version in the virtualenv is Python 3.4+. 确保virtualenv中的Python版本是Python 3.4+。
Django 2.0 only supports Python 3.4+, and functools.lru_cache
is only available in 3.2+. Django 2.0仅支持Python 3.4+,而
functools.lru_cache
仅支持3.2+。
To check the Python version in your current virtualenv: 要检查当前virtualenv中的Python版本:
python --version
To create a new virtualenv with python 3: 使用python 3创建一个新的virtualenv:
python3 -m venv venv --prompt=myenv
This error is because of wrong picking of pip and python version . 此错误是由于错误选择pip和python版本。 You can solve it by adding below lines in the ~/.bash_profile
您可以通过在〜/ .bash_profile中添加以下行来解决它
alias python='python3'
alias pip='pip3.6'
After that close the terminal and run the following command to install Django 之后关闭终端并运行以下命令来安装Django
pip install Django==2.0
对于最新版本的Django,需要python 3,因此请尝试安装
pip install django==1.11
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.