Ashish Acharya
Ashish Acharya

Reputation: 3399

virtualenv edits system-wide settings

I installed a new virtual environment using the following command:

sudo virtualenv --python=python3.4 mysite

Then, I edited the permissions of the newly created folder:

sudo chmod -R 777 mysite/

I then proceeded to activate the virtual environment:

source mysite/bin/activate

The virtualenv was activated with (mysite) showing up before the prompt.

On my system-wide python packages I have django version 1.7.1 installed. I wanted to install django 1.8 to the virtualenv. So, I did this:

sudo pip3 install django==1.8

But to my horror, it deleted django 1.7.1 from my system and installed 1.8 on the system, not just the virtualenv as I wanted.

I confirmed this by running:

python -c "import django; print(django.get_version())"

It returns 1.8 both when the virtualenv is activated as well as deactivated.

How do I install 1.8 only inside the virtualenv, without affecting the system-wide django version?

Upvotes: 0

Views: 318

Answers (3)

Parth Joshi
Parth Joshi

Reputation: 61

dont use sudo while installing djando via pip and also try to use sudo less for creating virtual env and for changing permissions. i have tried these way and have done it

Upvotes: 0

lmz
lmz

Reputation: 1580

My guess is that the environment variables that specify the python / pip to use (especially PATH) are not passed through sudo. Why do you have to sudo anything anyway? Just create the virtualenv as your user, source bin/activate as your user, and run pip as your user.

For more information: man sudoers and search for Command environment.

Upvotes: 1

moonstruck
moonstruck

Reputation: 2784

No need to use sudo virtualenv Use only virtualenv

Purpose of virtualenv is to get isolated python environment.

When you are inside virtualenv don't use sudo pip / sudo pip3. Use pip without sudo. sudo pip is used to install python packages system wide.

So, normal workflow is

virtualenv --python=python3.4 mysite
source mysite/bin/activate

pip install <package_name_version> like pip install django==1.8

Upvotes: 2

Related Questions