2

我从 Django 1.5.8 更新到 1.7:

pip install Django==1.7
Downloading/unpacking Django==1.7
  Downloading Django-1.7-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: Django
  Found existing installation: Django 1.5.8
    Uninstalling Django:
      Successfully uninstalled Django
  Rolling back uninstall of Django
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
    pycompile=self.pycompile,
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 247, in move_wheel_files
    clobber(source, dest, False, fixer=fixer, filter=filter)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 209, in clobber
    shutil.copy2(srcfile, destfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 130, in copy2
    copyfile(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/bin/django-admin.py'

Storing debug log for failure in /Users/stefanieness/Library/Logs/pip.log

这是我的错误信息。

但是当我跑步时

python
import django
print(django.get_version())

我得到1.7。我可以使用这样的版本还是必须重新安装它?它会起作用吗?

谢谢!

4

1 回答 1

4

这是因为你第一次安装 django 时,你安装了 django sudo pip install django,它已经以 root 用户(或超级用户)的身份在你的全局 Python 解释器中安装了 django。

你的全局 Python 解释器中只能有一个版本的 django,所以一旦你升级它,任何使用全局 Python 解释器(换句话说,不使用虚拟环境)的 django 应用程序都将自动升级到 1.7

如果您没有任何其他 django 项目,那么这实际上并没有任何负面影响 - 但作为最佳实践,您应该使用虚拟环境,以便您可以轻松测试库的版本。

为了解决您眼前的问题,您需要sudo pip install -U django将 django 升级到最新的稳定版本。

于 2014-09-20T14:47:09.840 回答