直到今天,我一直在使用django完全没有问题。它给了我一个现有项目的错误,但我最近尝试创建一个新项目,我仍然得到相同的错误。 我在ubuntu 14.04,django 1.7,我使用virtualenv和python 3(尽管我也尝试过使用python2 env)。
我收到此错误:
ubuntuuser@computer:~/tmp$
ubuntuuser@computer:~/tmp$ mkvirtualenv djerror
New python executable in djerror/bin/python
Installing setuptools, pip...done.
cd (djerror)ubuntuuser@computer:~/tmp$ cd borrar/
bin/ borrar/ include/ lib/ local/
(djerror)ubuntuuser@computer:~/tmp$ django-admin.py startproject djerror
(djerror)ubuntuuser@computer:~/tmp$ cd djerror/
(djerror)ubuntuuser@computer:~/tmp/djerror$ ls
djerror manage.py
(djerror)ubuntuuser@computer:~/tmp/djerror$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 1, in <module>
import collections
File "/usr/local/lib/python3.4/collections/__init__.py", line 17, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/dist-packages/reprlib.py", line 3, in <module>
from repr import *
ImportError: No module named 'repr'
(djerror)ubuntuuser@computer:~/tmp/djerror$
这是另一种给我带来同样错误的方法:
ubuntuuser@computer:~/tmp$ virtualenv djerror2
New python executable in djerror2/bin/python
Installing setuptools, pip...done.
ubuntuuser@computer:~/tmp$ cd djerror
ubuntuuser@computer:~/tmp/djerror$ cd ..
ubuntuuser@computer:~/tmp$ cd djerror2
ubuntuuser@computer:~/tmp/djerror2$ . bin/activate
(djerror2)ubuntuuser@computer:~/tmp/djerror2$ pip list
awsebcli (3.0.10)
cement (2.4.0)
Django (1.7.5)
django-bootstrap3 (5.1.1)
django-braces (1.4.0)
...
stevedore (1.2.0)
virtualenv (12.0.6)
virtualenv-clone (0.2.5)
virtualenvwrapper (4.3.2)
(djerror2)ubuntuuser@computer:~/tmp/djerror2$ django-admin.py startproject anothertest
(djerror2)ubuntuuser@computer:~/tmp/djerror2$ cd anothertest/
(djerror2)ubuntuuser@computer:~/tmp/djerror2/anothertest$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 1, in <module>
import collections
File "/usr/local/lib/python3.4/collections/__init__.py", line 17, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/dist-packages/reprlib.py", line 3, in <module>
from repr import *
ImportError: No module named 'repr'
(djerror2)ubuntuuser@computer:~/tmp/djerror2/anothertest$
是什么给出了?
编辑:
这就是我在〜/ .bashrc底部的内容。自从我安装ubuntu以来,我做了一些更改,但最近我更改了virtualenvwrapper的底部两行。
alias python='python3'
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
我认为文件的其余部分未受影响。
答案 0 :(得分:0)
经过一番摆弄(特别是在读完布兰登和丹尼尔的评论之后),我发现了这个问题。
我在某个时间点做错了什么,直到今天才引起问题。问题是python正在从python2路径加载一些模块,而其他模块从python3路径加载。
为了解决这个问题,我做了以下几点:
只有这样才能完成所有工作,虽然我可能已经过火了,但我更喜欢这样做,只是为了确定。