Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install virtualenv without using sudo?

I have easy_install and pip.

I had many errors on my Linux Mint 12, I just re-installed it and I want to install everything from scratch again.

This is one of the errors that I had. I received an interesting answer there:

Stop using su and sudo to run virtualenv.
You need to run virtualenv as your normal user.
You have created the virtualenv with sudo which is why you are getting these errors.

So how to install virtualenv without using sudo? Can i use pipor easy_install without using sudo? Or is there another way?

like image 375
Lynob Avatar asked Feb 19 '12 11:02

Lynob


People also ask

How do I install virtualenv in Python?

To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory . Activating and deactivating the virtual environment works the same way as it does for virtual environments in Python 3 (see above).


2 Answers

This solution is suitable in cases where no virtualenv is available system wide and you can not become root to install virtualenv. When I set up a debian for python development or deployment I always apt-get install python-virtualenv. It is more convenient to have it around than to do the bootstrap pointed out below. But without root power it may be the the way to go:

There is a bootstrap mechanism that should get you going.

Read: http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python

In essence you would do this in your home directory in a unix environment:

Given your python is version 2.6

      $ mkdir ~/bin     $ mkdir -p ~/lib/python2.6     $ mkdir -p ~/local/lib/python2.6/dist-packages     $ wget http://peak.telecommunity.com/dist/virtual-python.py     $ python virtual-python.py --no-site-packages     $ wget http://peak.telecommunity.com/dist/ez_setup.py     $ ~/bin/python ez_setup.py     $ ~/local/bin/easy_install virtualenv     $ ~/local/bin/virtualenv --no-site-packages thereyouare  

There may be room for optimization. I don't like the local path. Just bin and lib would be nice. But it does its job.

like image 91
itsafire Avatar answered Sep 22 '22 14:09

itsafire


The general idea is to install virtualenv itself globaly, i.e. sudo easy_install virtualenv or sudo pip install virtualenv, but then create the actual virtual environment ("run virtualenv") locally.

like image 22
ThiefMaster Avatar answered Sep 21 '22 14:09

ThiefMaster