安装Django Rest Framework时出错

时间:2016-06-01 15:48:01

标签: django python-2.7 ubuntu django-rest-framework

我正在尝试使用官方说明安装django rest框架:http://www.django-rest-framework.org/#installation

但这就是我在终端上看到的内容:

Collecting djangorestframework
Using cached djangorestframework-3.3.3-py2.py3-none-any.whl
Installing collected packages: djangorestframework
Exception:
Traceback (most recent call last):
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
ensure_dir(destdir)
File "/home/abduaziz/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/rest_framework'

我已经尝试了10次或更多次。此外,我无法克隆djangorestframework的git repo。伙计,我该怎么办?有没有其他方法可以安装它?

*我的笔记本电脑正在运行Ubuntu 16.04

1 个答案:

答案 0 :(得分:5)

看起来存在权限问题。您可以使用sudo进行安装,但我认为最好的方法是使用virtual environment,因为您不需要使用sudo来安装它。

所以,sudo pip install djangorestframework

或者为项目使用虚拟环境:

# set up a new environment (may need to change the path to python)
virtualenv -p /usr/bin/python2.7 venv
# get inside the virtual environment
source venv/bin/activate
# Install django and django rest framework
pip install django
pip install djangorestframework