django安装问题[python] [英] Problem with django installation [python]

查看:76
本文介绍了django安装问题[python]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

去年夏天,我想学习Web开发,所以我安装了Django 1.8(一个不稳定的版本).我没有点子就安装了它.我最近决定再试一次,但想使用稳定版本1.7.1进行操作,并希望使用pip进行安装以简化操作.

Last summer I wanted to learn to do web dev, so I installed Django 1.8, an unstable release. I installed it without pip. I recently decided to try again, but wanted to do work with the stable release, 1.7.1, and wanted to install with pip for simplicity.

我读到为了删除不带pip的Django,必须从/Library/Python/2.7/site-packages/删除整个.egg,所以我做到了.

I read that in order to remove Django that was installed without pip, one must delete the entire .egg from /Library/Python/2.7/site-packages/, so I did this.

从那时起,我一直在收到有趣的错误.当我发出"pip install django"时,我得到

Since then, I've been getting funny errors. When I issue 'pip install django', I get

bash-3.2$ pip install django
Downloading/unpacking django
  Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: 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 215, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in clobber
    os.makedirs(destdir)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'

当我检查虚假目录时,我发现/django不存在. 发出sudo将使错误消失,但是我发现我仍然无法启动django项目.

When I check the spurious directory, I find that /django doesn't exist. Issuing sudo will silence the errors, but I find that I still can't start a django project.

有没有人以前看过这个,或者有任何想法如何解决这个问题?

Has anyone seen this before or have any idea how to fix this?

推荐答案

这并不是真正的错误-由于您的普通用户帐户无法写入全局/Library文件夹,因此您正在从操作系统中获得此权限被拒绝的错误

This is not really an error - as your normal user account cannot write to the global /Library folder, you are getting this permission denied error from the operating system.

最佳做法是在称为虚拟环境中工作virtualenv的简称.这样可以确保在尝试使用Python软件包时,不会意外破坏Python在系统范围内的安装.

The best practice is to work in a virtual environment called virtualenv for short. This makes sure that when you are experimenting with Python packages, you don't accidentally corrupt the system-wide installation of Python.

在Mac(您正在使用)上,可能还有其他依赖于Python的系统实用程序,如果系统默认的Python损坏,它们可能会停止工作.

On a Mac (which you are using) there might be other system utilities that rely on Python and they may stop working if the system default Python is corrupted.

因此,第一步是在系统上全局全局安装virtualenv.为此,您需要超级用户权限,但这只能执行一次:

So the first step is to install virtualenv globally on your system. To do this, you need superuser permissions but this is done only once:

sudo easy_install virtualenv

以上将要求输入密码-只需输入您的普通用户密码即可.

The above will ask for a password - just enter your normal user password.

上述命令完成后,您的普通用户从命令行运行以下命令:

Once the above command finishes, as your normal user run the following from the command line:

$ virtualenv my_env  # This creates a new Python environment called my_env, completely
                     # separate from your system wide install.
$ source my_env/bin/activate # Activates the virtual envrionment
(my_env) $ pip install django # Install django in this new environment the (my_env)
                              # indicates you are working inside a virtual environment

...

(my_env) $ deactivate  # Deactivates the environment,
                       # returning you to the normal system Python
$

您在虚拟环境中安装的所有内容仅在虚拟环境中可用,因此在运行脚本时需要确保您在正确的环境中.

Anything you install in the virtual environment is only available within the virtual environment, so you need to make sure you are in the correct environment when running your scripts.

这篇关于django安装问题[python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆