简体   繁体   中英

How to install Django with pip inside a virtualenv in /var/www/html/project_name folder?

I'm using Ubuntu 15.04 with Python 2.7, pip 1.5.6 and virtualenv 1.11.6.

I will create a Django project inside /var/www/html/project_name (and work in that directory) for use it with Apache2.

I created a virtual environment named venv inside the project_name folder for syncing purposes.

With the virtual environment activated, I just cant't run pip install django because I get 'Permission denied' message. So I try the command sudo pip install django , but that will install Django globally.

So, running which pip , I get /var/www/html/project_name/venv/bin/pip .

But running sudo which pip , I get /usr/bin/pip .

Does someone get any idea about how it is possible to install Django (or any other package) inside the virtual environment?

PS: I know it's possible to run sudo venv/bin/pip install django , but it doesn't seem very useful.

Your trouble is presumably that you don't have write access to this /var/www/html/project_name directory. Your choices are:

  1. Change the permissions, recursively, so that you do have permissions to write to that directory.

  2. Run the following commands:

.

$ sudo su
# . venv/bin/activate
# pip install

Just to add what everyone's been saying and I sort of skimmed over: NEVER EVER put sensitive things (that includes your django project) under the document root. You can store it under something like /var/www/scripts or something, but don't put it under the document root.

Another way of deploying is using something like gunicorn as the "main" webserver and then just having whatever world visible webserver (like apache) reverse proxy to gunicorn. I've done this with nginx and it's fairly easy to setup, the only down side is then you have to setup something extra in your system's init scripts to start up gunicorn.

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.

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