简体   繁体   English

django安装:不能用pip在linux上安装django(ubuntu)

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

I tried to install django on ubuntu using pip. 我尝试使用pip在ubuntu上安装django。 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使用虚拟环境,如下所示:

$ 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: 键入deactivate以退出虚拟环境:

(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. 您尝试安装django“usr / local / lib / ...”的位置是root owanership location。因此,对于每个命令,您都需要sudo。

Instead of that you can follow these stpes 而不是你可以遵循这些stpes

1.Install vitrual environment 1.安装玻璃环境

$ sudo pip install virtualenv

2.Create virtual env 2.创建虚拟环境

$ virtualenv -p python3 testEnv 

(Dont use sudo here it will make the environment root ownership.Here i am creating python 3 environment) (不要在这里使用sudo它将使环境根所有权。在这里我创建python 3环境)

3.Activate that env using following command 3.使用以下命令激活env

$ source testEnv/bin/activate

4. Install django using the command 4.使用命令安装django

$ pip install django

5.Using the follwing command you can check the installed packages in that environment 5.使用follwing命令可以检查该环境中已安装的软件包

$ pip freeze

note:It is better to use pip commands without sudo.If we are using sudo that package will change to root ownership 注意:最好使用没有sudo的pip命令。如果我们使用sudo,那么包将更改为root所有权

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM