6

My goal is to serve a hello world Django app that uses postgres on an EC2 instance running Ubuntu. I logged in via ssh and cloned a git repo containing a Django project with this requirements.txt:

Django==1.8.2  
djangorestframework==3.1.2  
psycopg2==2.6

I created a virtualenv and then, when I ran (ec2_deploy_test)ubuntu@ip-172-31-22-100:~/ec2-deploy-test$ pip install -r requirements.txt, this exception was thrown:

Collecting psycopg2==2.6 (from -r requirements.txt (line 3)) /home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading psycopg2-2.6.tar.gz (367kB) 100% |████████████████████████████████| 368kB 785kB/s Building wheels for collected packages: psycopg2 Exception: Traceback (most recent call last): File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main status = self.run(options, args) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/commands/install.py", line 291, in run wb.build(autobuilding=True) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/wheel.py", line 753, in build ensure_dir(output_dir) File "/home/ubuntu/Envs/ec2_deploy_test/local/lib/python2.7/site-packages/pip/utils/init.py", line 70, in ensure_dir os.makedirs(path) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in makedirs makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in makedirs makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 150, in makedirs makedirs(head, mode) File "/home/ubuntu/Envs/ec2_deploy_test/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/ubuntu/.cache/pip/wheels/ab'

Then I ran (ec2_deploy_test)ubuntu@ip-172-31-22-100:~/ec2-deploy-test$ sudo pip install -r requirements.txt and psycopg2 installed successfully.

Why would I need root permissions to install a python package in my virtual environment? I am new to Linux and sysadmin in general so all advice is welcome. Thanks in advance.

madzohan
  • 11,488
  • 9
  • 40
  • 67
Brandon Brown
  • 331
  • 6
  • 16
  • id you do sudo, it is not actually installing it in your virtualenv. Also if you create your virtualenv as root, then the users will not have permissions to install all the packages – Abhishek May 29 '15 at 21:36

2 Answers2

6

For some reason you don't have an access to create a directory inside the /home/ubuntu/.cache/pip/wheels/ab. Normally this problem shouldn't appear; anyway, since it happened, just change the rights of the .cache directory recursively. I guess that the problem is an ownership, so try to launch the command sudo chown -R <USERNAME> ~/.cache/pip, where the <USERNAME> supposed to be the name of your user.

An advice — try to not launch an apps from root without a real need in this. Most probably that the directory to which you have no an access was created by some application being run with root rights — and now an ownership messed.

Hi-Angel
  • 4,933
  • 8
  • 63
  • 86
1

I assume you used virtualenv -p /usr/bin/python3.4 env, I had the same problem

Its python 3 and might have nothing to do with permissions or root if you tried Angles recommendation and it does not work. You need to install python3-dev ... Or just stick with python2. hope that helps

heres the link: Trouble with psycopg2 in virtualenv python3 for use with Django

Community
  • 1
  • 1
Curious Lambda
  • 537
  • 2
  • 7
  • 21
  • I don't think you indeed had the same problem. The question you linked have the error different from the one here. There it couldn't find a module, but the error here is «Permission denied». – Hi-Angel Dec 03 '15 at 12:02