Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django installation: cannot use pip to install django on linux(ubuntu)

Tags:

python

pip

django

I tried to install django on ubuntu using pip. but unfortunately I got error like this. can someone explain this and tell me some ways to fix this?

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
like image 333
Junchao Gu Avatar asked Nov 28 '22 17:11

Junchao Gu


2 Answers

Don't use sudo use a virtual environment instead, like this:

$ 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

When you are finished; type deactivate to exit the virtual environment:

(django_env)/projects/foo $ deactivate
/projects/foo $
like image 176
Burhan Khalid Avatar answered Dec 06 '22 09:12

Burhan Khalid


Try sudo pip install django instead.

like image 24
Robert T. McGibbon Avatar answered Dec 06 '22 10:12

Robert T. McGibbon