Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django not installing in virtualenv

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?

like image 853
user2817200 Avatar asked Feb 22 '14 21:02

user2817200


1 Answers

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
like image 141
praveen Avatar answered Oct 11 '22 17:10

praveen