Django not installing in virtualenv

2019-02-14 11:44发布

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?

1条回答
孤傲高冷的网名
2楼-- · 2019-02-14 12:27

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
查看更多
登录 后发表回答