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('rn', '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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 $
Method 2
Try sudo pip install django instead.
Method 3
The location which you are trying to install django “usr/local/lib/…” is root owanership location.So for every command you would require
sudo.
Instead of that you can follow these stpes
1.Install vitrual environment
$ sudo pip install virtualenv
2.Create virtual env
$ virtualenv -p python3 testEnv
(Dont use sudo here it will make the environment root ownership.Here i am creating python 3 environment)
3.Activate that env using following command
$ source testEnv/bin/activate
4. Install django using the command
$ pip install django
5.Using the follwing command you can check the installed packages in that environment
$ pip freeze
note:It is better to use pip commands without sudo.If we are using sudo that package will change to root ownership
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0