Using virtualenv to bypass sudoer issues

Cameron Simpson cs at zip.com.au
Sat Feb 8 04:32:22 CET 2014


On 07Feb2014 19:03, Asaf Las <roegltd at gmail.com> wrote:
> On Saturday, February 8, 2014 3:18:02 AM UTC+2, Cameron Simpson wrote:
> > On 06Feb2014 18:32, Jean-Michel Pichavant <je... at sequans.com> wrote:
> > 
> > > Assuming I have a debian workstation for which I don't have any
> > > sudo rights, in order to be able to install / remove python packages,
> > > should I be using virtualenv ? Is it a suited solution ?
> > 
> > It is well suited.
> > 
> > You can also do far simpler (and far smaller setups) like this:
> >   mkdir -p $HOME/lib/python
> > and in your environment (eg $HOME/.profile or $HOME/.bash_profile) add:
> >   PYTHONPATH=$HOME/lib/python:$PYTHON_PATH
> >   export PYTHONPATH
> > and simply install (copy) packages into that directory.
> > This is conceptually the same as having a $HOME/bin with commands
> > or your own in it, etc.
[...]
> 
> Does this approach work with mixed packages comprising non python
> code? 

Persuming you are asking about "just make a lib directory and point
$PYTHONPATH at it" instead of virtualenv, in principle yes.
But it is more work; virtualenv is essentially a well standardised and more
thorough version.

Most such mixed packages install with a setup.py that compiles the
relevant bits, and you'll need to tell setup.py where to install
things, so it is not as easy as just copying in the files.

I think such packages are about the point where I would consider
virtualenv; once you have the virtualenv set up, installing packages
is more automatic.

For pure python packages, just copying them into your personal lib
works well, and is very simple. As soon as you get mixed packages,
it is probably more worthwhile to use virtualenv. I think.

Virtualenv looks like a bit of a leap to set up to start with, but
I found it easier than I expected. As I recall, you can do two basic
types of virtualenv: a "complete" one which installs copies of all
the system packages, or a much smaller one that itself hooks into
the system python packages.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Life IS pain, highness...  anyone who tries to tell you different is
trying to sell you something.   - Wesley, The_Princess_Bride



More information about the Python-list mailing list