Step by step instructions for creating a relocatable environment using virtualenvwrapper

163 views
Skip to first unread message

John Gluck

unread,
Sep 22, 2011, 2:47:34 PM9/22/11
to virtualenvwrapper
Hey,

I'm a python noob looking for step by step instructions on how to
create a virtualenv with preinstalled packages (like from pip or
easy_install) that can be checked into source control and checked out,
built and worked on.

I used cpvirtualenv <source> <target> but when I do a find on the
target, I see that my homedirectory is still in the .pyc files. How
do I get it out of there? Or does it matter. The apps on the
virtualenv aren't running correctly (Specifically, I'm using RIDE and
when it fails to find the libraries I installed in it). How can I
tell if this is a problem I created or if this is an issue in RIDE?

Help please

Federico Maggi

unread,
Sep 22, 2011, 4:09:29 PM9/22/11
to virtuale...@googlegroups.com
On Sep 22, 2011, at 8:47 PM, John Gluck wrote:

> I used cpvirtualenv <source> <target> but when I do a find on the
> target, I see that my homedirectory is still in the .pyc files. How
> do I get it out of there? Or does it matter. The apps on the
> virtualenv aren't running correctly (Specifically, I'm using RIDE and
> when it fails to find the libraries I installed in it). How can I
> tell if this is a problem I created or if this is an issue in RIDE?

if you need to relocate your virtualenv that's one story. If you instead need to re-create a virtualenv, say B, with the same exact packages of another virtualenv, say A, all you have to do is the following:

$ source ~/ve/A/bin/activate
(A) $ pip freeze -r > requirements_A.txt
$ virtualenv --no-site-packages ~/ve/B
(B) $ pip install -r requirements_A.txt

You may also want to check out the handy virtualenvwrapper

Cheers,
-F

Doug Hellmann

unread,
Sep 22, 2011, 6:24:26 PM9/22/11
to virtuale...@googlegroups.com

On Sep 22, 2011, at 2:47 PM, John Gluck wrote:

> Hey,
>
> I'm a python noob looking for step by step instructions on how to
> create a virtualenv with preinstalled packages (like from pip or
> easy_install) that can be checked into source control and checked out,
> built and worked on.

Hi, John!

My preferred way to manage something like what you're doing is to check in a requirements file that can be fed to pip to install my dependencies. The requirement file can be given to pip after you create a fresh environment, or using the new -r option to mkvirtualenv you can create the env and install the requirements all with one command. If you don't want to download packages from the internet every time, it is possible to set up a local download server or cache directory (check the pip site or mailing list for instructions).

> I used cpvirtualenv <source> <target> but when I do a find on the
> target, I see that my homedirectory is still in the .pyc files. How
> do I get it out of there? Or does it matter. The apps on the
> virtualenv aren't running correctly (Specifically, I'm using RIDE and
> when it fails to find the libraries I installed in it). How can I
> tell if this is a problem I created or if this is an issue in RIDE?

I don't know what RIDE is. Does it work with virtualenv? You might need to ask this part of your question on the virtualenv mailing list (the wrappers are just some shell functions that invoke virtualenv, so they don't really change or control its behavior).

I hope that helps,
Doug

Erik Bray

unread,
Sep 23, 2011, 12:31:32 PM9/23/11
to virtuale...@googlegroups.com
On Thu, Sep 22, 2011 at 6:24 PM, Doug Hellmann <doug.h...@gmail.com> wrote:
>
> On Sep 22, 2011, at 2:47 PM, John Gluck wrote:
>
>> Hey,
>>
>> I'm a python noob looking for step by step instructions on how to
>> create a virtualenv with preinstalled packages (like from pip or
>> easy_install) that can be checked into source control and checked out,
>> built and worked on.
>
> Hi, John!
>
> My preferred way to manage something like what you're doing is to check in a requirements file that can be fed to pip to install my dependencies. The requirement file can be given to pip after you create a fresh environment, or using the new -r option to mkvirtualenv you can create the env and install the requirements all with one command. If you don't want to download packages from the internet every time, it is possible to set up a local download server or cache directory (check the pip site or mailing list for instructions).

But is it possible to have a cache of built packages as well (rather
than just the source code)? I've never figured out a way to do that
with pip. Reinstalling all packages from scratch is a huge pain if
you have a long list of requirements, or when one of this requirements
is, say, numpy :)

My solution for that, by the way, is the have a mostly clean Python
install that has numpy, matplotlib, and all the other "difficult"
packages already installed, and I make my virtualenvs off that Python
(with site-packages enabled). But it would be nice if it were easier
to just copy them around, though that's not really a problem for
virtualenvwrapper to solve.

Erik

Doug Hellmann

unread,
Sep 23, 2011, 8:29:37 PM9/23/11
to virtuale...@googlegroups.com

On Sep 23, 2011, at 12:31 PM, Erik Bray wrote:

> On Thu, Sep 22, 2011 at 6:24 PM, Doug Hellmann <doug.h...@gmail.com> wrote:
>>
>> On Sep 22, 2011, at 2:47 PM, John Gluck wrote:
>>
>>> Hey,
>>>
>>> I'm a python noob looking for step by step instructions on how to
>>> create a virtualenv with preinstalled packages (like from pip or
>>> easy_install) that can be checked into source control and checked out,
>>> built and worked on.
>>
>> Hi, John!
>>
>> My preferred way to manage something like what you're doing is to check in a requirements file that can be fed to pip to install my dependencies. The requirement file can be given to pip after you create a fresh environment, or using the new -r option to mkvirtualenv you can create the env and install the requirements all with one command. If you don't want to download packages from the internet every time, it is possible to set up a local download server or cache directory (check the pip site or mailing list for instructions).
>
> But is it possible to have a cache of built packages as well (rather
> than just the source code)? I've never figured out a way to do that
> with pip. Reinstalling all packages from scratch is a huge pain if
> you have a long list of requirements, or when one of this requirements
> is, say, numpy :)

A relocatable virtualenv may do something like what you want, but that's really a virtualenv feature and doesn't have anything to do with the wrappers.

> My solution for that, by the way, is the have a mostly clean Python
> install that has numpy, matplotlib, and all the other "difficult"
> packages already installed, and I make my virtualenvs off that Python
> (with site-packages enabled). But it would be nice if it were easier
> to just copy them around, though that's not really a problem for
> virtualenvwrapper to solve.

I do the same thing with tools like enchant. :-)

Doug

Reply all
Reply to author
Forward
0 new messages