简体   繁体   English

如何在Mac上完全重新安装Django

[英]How can I completely reinstall Django on a Mac

I'm a complete newcomer to Python and the Django framework so please be gentle. 我是Python和Django框架的新手,所以请保持谨慎。

I'm on a Mac 10.8 and MAMP. 我使用的是Mac 10.8和MAMP。 I was following the tutorial and installed the latest stable version (1.5) of Django using pip thanks to the instructions on this page. 由于本页面上的说明,我正在按照本教程进行操作并使用pip安装了Django的最新稳定版本(1.5)。 For some reason, I decided immediately after this to install instead the development version (1.6dev) by cloning the git repository using these instructions. 出于某种原因,在此之后,我立即决定通过使用这些说明克隆git存储库来代替安装开发版本(1.6dev)。 At this point, everything was OK and running the following code: 至此,一切正常,并运行以下代码:

>>> import django
>>> print(django.get_version())

printed out version 1.6dev-blahblahblah. 打印出1.6dev-blahblahblah版本。

I then tried to create my first project with this command: 然后,我尝试使用此命令创建我的第一个项目:

django-admin.py startproject mysite

It worked. 有效。 Here's where I did something stupid. 这是我做蠢事的地方。 I changed my mind at this point and thought it might be better to stick with the stable development version rather than the bleeding edge version and so I tried to remove the development version. 我此时改变了主意,并认为坚持使用稳定的开发版本比使用最新版本更好,因此我尝试删除开发版本。 All I did was delete the django folder found after typing this command: 我要做的就是删除键入以下命令后找到的django文件夹:

python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"

I then reran pip and it said everything was installed correctly. 然后我重新运行pip,并说一切都已正确安装。 When I get the version number from the Python interpreter I get this output: 当我从Python解释器获得版本号时,得到以下输出:

>>> import django
>>> print(django.get_version())
1.5.1

However, when I try to create a new project I get the following error: 但是,当我尝试创建一个新项目时,出现以下错误:

django-admin.py startproject mysite
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 4, in <module>
from pkg_resources import require; require('Django==1.6.dev20130425172216')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2607, in <module>
parse_requirements(__requires__), Environment()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: Django==1.6.dev20130425172216
Garrys-MacBook-Air-2:~ Garry$ 

Sorry for being stupid but how can I fix this?? 对不起,我很傻,但是我该如何解决呢?

Thanks 谢谢

File "/usr/local/bin/django-admin.py", line 4, in <module>
from pkg_resources import require; require('Django==1.6.dev20130425172216')

It looks like the django-admin.py is still the one from version 1.6blabla I would try to uninistall everything via pip (1.5 and/or 1.6), make sure /usr/local/bin/django-admin.py was also removed, and reinstall 1.5 via pip again. 看起来django-admin.py仍然是1.6blabla版本中的那个,我会尝试通过pip (1.5和/或1.6) 取消所有安装 ,确保还删除了/usr/local/bin/django-admin.py ,然后再次通过pip重新安装1.5。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM