我试图使用pip在ubuntu上安装django。但不幸的是我遇到了这样的错误。有人可以解释一下并告诉我一些解决方法吗?
error: could not create '/usr/local/lib/python2.7/dist-packages/django': Permission denied ---------------------------------------- Command /usr/bin/python -c "import setuptools;__file__='/home/franklingu/build/django /setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-W5MhGe-record/install-record.txt failed with error code 1 Storing complete log in /home/franklingu/.pip/pip.log
不要使用sudo而是使用虚拟环境,如下所示:
$ sudo apt-get install python-virtualenv $ mkvirtualenv django_env $ source django_env/bin/activate (django_env) $ pip install django (django_env) $ cd $HOME (django_env) $ mkdir projects (django_env) $ cd projects (django_env)/projects $ django-admin.py startproject foo (django_env)/projects $ cd foo (django_env)/projects/foo $ python manage.py runserver
完成后;键入deactivate以退出虚拟环境:
(django_env)/projects/foo $ deactivate /projects/foo $