简体   繁体   中英

issue with pip installing django in ubuntu server virtualenv

I created a virtualenv on and EC2 instance, and have installed ubuntu server.

I created a non root user "ivan" as gave is sudo permission:

usermod -a -G sudo ivan

When I activate the virtualenv and run this command with the user ivan:

pip install django==1.7  

I get various permission related errors:

The directory '/home/ivan/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.

as well as more importantly

  PermissionError: [Errno 13] Permission denied: '/home/ivan/sites/mysite/virtualenv/lib/python3.4/site-packages'

While the virtualenv was activated, I tried

sudo pip install django==1.7

but that installed django to the system folders, and not in the virtualenv.

I also tried changing to the root user and activating the virtualenv used the pip install command again with this result (since it already installed to the system with the sudo pip install command):

Requirement already satisfied  

I changed the permission on the site-packages to 777, then the error 13 permission error changed to a different file:

  PermissionError: [Errno 13] Permission denied: '/home/ivan/sites/mysite/virtualenv/bin/django-admin.py'

Questions:

1) Is using chmod for every directory or file that comes up with a permission error is a sloppy way of doing things? Is there a better way? Do I change the /home/ or some other directory permissions when I first start a ubuntu server?

2) is using a 777 permission on these files and directories the web server to attack?

3) should I chmod the files and directories I have these issues with to 777, then change them back to 755?

This is my first attempt at setting up a web server, and I would appreciate any help.

Ivan

You need to change owner of files and directories inside /home/ivan/ directory to ivan . Try this:

sudo chown -R ivan:ivan /home/ivan

Also, since some packages are probably partly-installed, I would recommend to recreate virtualenvs and reinstall python packages from ivan user.

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