5

I am using Linux (Lubuntu) and have installed virtualenv like so

sudo easy_install virtualenv

and then did

mkdir virt_env

and created a folder which holds the virtualenv's. Next, I did

virtualenv virt_env/virt1 --no-site-packages

and created the environment. Next, I activated it like so:

source virt_env/virt1/bin/activate

and all went well. Then, I did

sudo pip install Django

and it said it is sucesfully installed. I then did

pip freeze

and Django was not listed. I deactivated the virtualenv and did

pip freeze

and Django was there. Why did it install Django systemwide rather than in the virtualenv? I then activated the virtualenv again and tried

sudo pip install Django

and it said

Requirement already satisfied (use --upgrade to upgrade): Django in /usr/local/lib/python2.7/dist-packages

how do I install it in the virtualenv and not systemwide?

user2817200
  • 1,097
  • 2
  • 18
  • 38
  • 1
    Don't install with `sudo`. One of the reasons for using a virtualenv in the first place is that you install things directly in there, as the current user. I'm not sure, but using `sudo` might ignore the virtualenv at all, hence your problem. – Daniel Roseman Feb 22 '14 at 21:48
  • @DanielRoseman if I do just 'pip install Django' in the virtualenv it gives an error and the last few lines in the traceback is "File "/home/vert_env/virt1/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/vert_env/virt1/build' Storing debug log for failure in /home/ayman/.pip/pip.log"" – user2817200 Feb 22 '14 at 21:55

1 Answers1

8

Try cd'ing to the virt1 directory and then running "bin/pip install django". You are using your system wide pip instead of the one in virt1/bin.

virtualenv creates four directories(bin, include, lib, local) when you initialize it in a directory. "lib" is the directory where virtualenv keeps all your virtualenv specific python packages. Use bin/pip to install django and you will find Django it in lib/python2.x/site-packages/

When looking for python packages installed in the environment, use "bin/pip freeze" instead of the "pip freeze".

Steps:

>> mkdir virtualenv_test
>> cd virtualenv_test
>> virutalenv . --no-site-packages
>> source bin/activate
>> bin/pip install django
>> bin/pip freeze
praveen
  • 3,193
  • 2
  • 26
  • 30
  • if I do just "bin/pip install Django", it gives an error and the last few lines of the traceback is "File "/home/vert_env/virt1/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/vert_env/virt1/build' Storing debug log for failure in /home/ayman/.pip/pip.log"" – user2817200 Feb 22 '14 at 21:57
  • can you try repeating all the steps in a new directory? – praveen Feb 22 '14 at 21:59
  • ah wait, if I do 'sudo bin/pip install Django' while the virtualenv is activated, it does install it in the virtualenv.. is there a reason I should try getting it to work without using sudo? – user2817200 Feb 22 '14 at 22:01
  • 1
    yes, because since you are the user who created that directory and initialized the virtualenv environment, you have the permission to install Django in lib/ directory. All the steps should work without using 'sudo' – praveen Feb 22 '14 at 22:04
  • hm okay, since I got it to work with sudo, I am now trying to uninstall it and reinstall it without sudo but when I try to uninstall it without sudo, it gives the same 'Permission denied' error as I commented above. EDIT: I will try what you suggest right now. – user2817200 Feb 22 '14 at 22:07
  • sir just delete that directory and repeat the steps I updated in my answer above – praveen Feb 22 '14 at 22:08
  • hm okay, I think you've found the problem. I was creating the virtualenv_test folder in my home directory and it said permission denied to then I created the directory and the environment AFTER I did sudo su.. is there any way for me to be able to create files in my home directory without doing 'sudo su'? Or is it not possible to create folders in the home directory without doing sudo su? – user2817200 Feb 22 '14 at 22:10
  • 1
    creating directories in /home/ does require admin privileges since it is the region not intended to be used by normal users. You can do anything without sudo in /home/. So I guess the answer is "No" – praveen Feb 22 '14 at 22:14