Question

I'm setting up a new system for a group of Python rookies to do a specific kind of scientific work using Python. It's got 2 different pythons on it (32 and 64 bit), and I want to install a set of common modules that users on the system will use.

  • (a) Some modules work out of the box for both pythons,
  • (b) some compile code and install differently depending on the python, and
  • (c) some don't work at all on certain pythons.

I've been told that virtualenv (+ wrapper) is good for this type of situation, but it's not clear to me how.

  1. Can I use virtualenv to set up sandboxed modules across multiple user accounts without having to install each module for each user?
  2. Can I use virtualenv to save me some time for case (a), i.e. install a module, but have all pythons see it?

I like the idea of isolating environments, and then having them just type "workon science32", "workon science64", depending on the issues with case (c).

Any advice is appreciated.

Était-ce utile?

La solution

With virtualenv, you can allow each environment to use globally installed system packages simply by omitting the --no-site-packages option. This is the default behavior.

If you want to make each environment install all of their own packages, then use --no-site-packages and you will get a bare python installation to install your own modules. This is useful when you do not want packages to conflict with system packages. I normally do this just to keep system upgrades from interfering with working code.

I would be careful about thinking about these as sandboxes, because they are only partially isolated. The paths to python binaries and libraries are modified to use the environment, but really that is all that is going on. Virtualenv does nothing to prevent code running from doing destructive things to the system. Best way to sandbox is set Linux/Unix permissions properly, and give them their own user accounts.

EDIT For Version 1.7+

The default for 1.7 is to not include system packages, so if you want the behavior of using system packages, use the --system-site-packages option. Check the docs for more info.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top