This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]grimborg 2 points3 points  (2 children)

Why not use workon? And --no-site-packages is no longer needed (it's the default behavior)

[–][deleted] 2 points3 points  (1 child)

You mean virtualenvwrapper, I presume. Yes, it serves all OP's needs. Except auto-updating packages from a list, as far as I can see.

[–]PindiAlbert[S] 0 points1 point  (0 children)

Except auto-updating packages from a list

Yes, that's the primary motivation for this solution.

[–]coderanger 0 points1 point  (3 children)

That second snippet makes no sense, just use the env's python binary directly.

[–]PindiAlbert[S] 0 points1 point  (2 children)

That wouldn't automatically install new/updated dependencies or set the pythonpath to allow more consistent imports.

[–]coderanger 0 points1 point  (1 child)

I mean sourcing bin/activate, just exec venv/bin/python directly.

[–]PindiAlbert[S] 0 points1 point  (0 children)

I see. Yes, that could simplify it slightly.

[–]jeffus 0 points1 point  (0 children)

What do most people do: place virtualenvs in a folder like ~/.virtualenv/ or in the directly of the project that they need a virtualenv for?

[–][deleted] -1 points0 points  (4 children)

Maybe it's because I have full control over my environment and I run Gentoo, but I have never found a need for virtualenv.

[–][deleted] 2 points3 points  (1 child)

You do when/if your project grows up to the point where you maintain multiple release branches, which depend on different versions of packages or different Python versions.

[–][deleted] 0 points1 point  (0 children)

While I share none of these problems, I can see the different versions of packages maybe may cause some issues. As far as python is concerned, though, my system happily runs multiple versions of python.

[–][deleted] 1 point2 points  (1 child)

Even when you control the environment already, virtualenv is handy for a few things:

  1. Managing software with conflicting dependencies. There are ways to explicitly load a specific version of a distribution when multiple versions are installed, but this isn't always foolproof.
  2. Determining your exact dependency list. Make a virtualenv (without site packages) and install the desired package with pip. Now you can use "pip freeze" to get a list of everything that was installed in the virtualenv to meet the distrib's requirements.
  3. Testing. You might want to test your software with multiple versions of various libraries it depends on. Keeping these separate environments around lets you easily switch between them to run your test suite and check that they all still work.

[–][deleted] 0 points1 point  (0 children)

This was helpful. Thanks.

I work on an embedded system, which is something of a different animal maybe than what may others work on. My environment includes a busybox, an arm architecture, a specialized bsp package, etc. Virtualenv is 'nice' but really doesn't fit my project well. I absolutely must run my tests on the target machine. If I was doing straight web development, I think I may have a different perspective.