简体   繁体   English

安装Django时出错

[英]Error when installing Django

I am trying to install Django on my a new mac which I got yesterday. 我试图在我昨天得到的新Mac上安装Django。 I am switching over from a Windows, but I didn't think that should have been much of an issue. 我正在从Windows切换,但我不认为这应该是一个很大的问题。 Every time I try install either the version 1.6.5 or the development version I keep on getting the same error: 每次我尝试安装版本1.6.5或开发版本时我都会遇到同样的错误:

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'

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

尝试使用sudo,它对我有用:

sudo pip install django

This error is because of your account does not have any right access to the installation directory. 此错误是因为您的帐户没有任何权限访问安装目录。 If the installation directory is a system owned directory, you may need to sign in as a administrator or "root" account . 如果安装目录是系统拥有的目录,则可能需要以administrator"root" account登录。

To sign in as a root : 以root身份登录:

sudo su

by using setup_tool you can easily upgrade the version of django. 通过使用setup_tool您可以轻松升级django的版本。 On Linux, you can install easy_install with: 在Linux上,您可以使用以下命令安装easy_install

sudo apt-get install python-setuptools

Then run: 然后运行:

 sudo easy_install --upgrade django

This will remove current django path from PYTHON_PATH , add its own path, and upgrade django to its newest version. 这将从PYTHON_PATH删除当前的django路径,添加自己的路径,并将django升级到其最新版本。

Creating a vitualenv has solved this problem for me. 创建一个vitualenv已经为我解决了这个问题。 I recently installed Python3.4 and wanted to use Django 1.8.X with this. 我最近安装了Python3.4并希望使用Django 1.8.X。 Sudo pip install as expected allowed Django to be imported and used with the default python 2.7 but trying to import generated an error. 正如预期的那样,Sudo pip安装允许导入Django并与默认的python 2.7一起使用,但尝试导入生成的错误。 My solution pooled from different sites - after about 3 hours of investigation yielded... 我的解决方案汇集在不同的网站上 - 经过大约3个小时的调查后产生了......

At the terminal: 在终端:

$ virtualenv -p /usr/local/bin etc/pythonX.X env

this creates a virtualenv called env but specifically uses the python version that you want. 这会创建一个名为env的virtualenv,但是专门使用你想要的python版本。 to check where your python version is located $which pythonX.X then use that path with the -p flag. 检查python版本所在的位置$ pythonX.X然后使用带-p标志的路径。 Check that you're using the right python by default using $python -V. 使用$ python -V检查您是否正在使用正确的python。 Then 然后

$ source env/bin/activate

at this point you can pip install yourrequiredpackage 此时你可以pip安装你需要的包

$pip install django 

and all good...running: 一切都很好......跑步:

$python 
>>>import django
>>>django.VERSION

showed it was imported successfully. 显示它已成功导入。 I hope this helps - first post on S/O so hope i have the style for answering right and it helps! 我希望这有帮助 - 首先发布S / O,所以希望我有正确回答的风格,这有帮助! all commments welcome 所有的交流都欢迎

You are trying to install python at the global python level and need root permissions to install additional libraries. 您正在尝试在全局python级别安装python并需要root权限才能安装其他库。 You can sudo pip install django to get around this. 你可以sudo pip install django来解决这个问题。

The best practice, however, is to use virtual environments. 但是,最佳做法是使用虚拟环境。 This allows you to work on multiple python projects, each with their own collection of libraries. 这允许您处理多个python项目,每个项目都有自己的库集合。 https://virtualenv.pypa.io/en/latest/ https://virtualenv.pypa.io/en/latest/

It's easy to set up: 它很容易设置:

First install pip, then virtualenv, and, if you'd like, install virtualenvwrapper: 首先安装pip,然后是virtualenv,如果你愿意的话,安装virtualenvwrapper:

sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
mkdir ~/.virtualenv

Add this to your ~/.profile 将其添加到〜/ .profile中

export WORKON_HOME=~/.virtualenv
source /usr/local/bin/virtualenvwrapper.sh

And you are set. 你就定了。 Create a new virtual environment called "temp" with: 使用以下命令创建名为“temp”的新虚拟环境:

mkvirtualenv temp

To start working in the environment: 要开始在环境中工作:

workon temp

From here you can pip install django as your current user. 从这里你可以pip install django作为当前用户。 To leave the virtualenv, simply type: 要离开virtualenv,只需输入:

deactivate

Full instructions here: http://virtualenvwrapper.readthedocs.org/en/latest/install.html 完整说明: http//virtualenvwrapper.readthedocs.org/en/latest/install.html

I have faced the same type of problem while installing on High Sierra. 在High Sierra上安装时遇到了同样的问题。 In my case, it was the pip version issue. 就我而言,这是pip版本问题。 Even 甚至

pip install --upgrade pip install --upgrade

wasn't able to upgrade the pip version. 无法升级点数版本。 So I have removed the old pip/pip2.7/pip3 from the folder and initiated a fresh refresh. 所以我从文件夹中删除了旧的pip / pip2.7 / pip3并启动了新的刷新。 That installed the new pip version 18. 安装了新的pip版本18。

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then, 然后,

python get-pip.py python get-pip.py

After that, it was a cakewalk. 在那之后,这是一个蛋糕。

Before installing, check your default python version using 在安装之前,请使用检查您的默认python版本

which python 哪个python

command. 命令。 In case it is 3, you are good to go. 万一它是3,你很高兴。 Otherwise, open the bash profile and change the default python version. 否则,打开bash配置文件并更改默认的python版本。 (not recommended though). (不推荐)。

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

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