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
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 $
试试sudo pip install django
。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.