Normally, venvs don't do this, as a way to keep their package namespaces clean. However, if you create a venv with the -system-site-packages option, programs running in that venv will also be able to see packages installed in the underlying Python installation. Apps that run in the venv can only "see" packages installed to the venv. Normally, when created, they don't use the underlying Python installation's site packages directory. One way to handle this is to take advantage of a not-widely-known feature of Python virtual environments. What if we have multiple projects that all need to share the same version of some package that happens to be really large-say, hundreds of megabytes? Here's a problem that's growing more common in this age of installing big Python packages like TensorFlow. Do share big packages across environments-but carefully But that requires you stay on top of the requirements for those projects as a group. If you have multiple projects that use the same versions of the same packages, and do so consistently, then you may be able to share a venv between them without ill effects. These installs are one-time costs, so there’s not much point in trying to ameliorate them. If your project has requirements.txt or Pipfile files, it’s trivially easy to set up a virtual environment for the project and install what it needs with a couple of commands. Two, the convenience and saved disk space will be marginal. The whole point of virtual environments is to isolate each project from other projects and their quirks. One, it’s all too likely that one of the projects in question will suddenly have requirements that break the other project. This is a bad idea for plenty of reasons, but two will suffice. If you have multiple projects that have roughly the same requirements, it might seem like a good idea to create a single virtual environment that both projects can share. Don’t share virtual environments between projects Use a name that describes your project unambiguously. This can have unpredictable effects on imports later. This tool allows you to manage all the virtual environments in your workspace from a single, central command-line application.Ī word of advice on creating virtual environments: Don’t name the directory of your virtual environment venv-or, for that matter, the name of any other package you want to use in the virtual environment. One way to make virtual environments less burdensome is to use virtualenvwrapper. (However, this only works if that package set is perfectly consistent and never changes more on this later.) Do use virtualenvwrapper to manage Python virtual environments Plus, if you have multiple tasks that share a common set of packages, you can use the same virtual environment for those tasks. But disk space is ridiculously cheap these days, and removing a virtual environment is as blissfully simple as deleting its directory (no side effects). Some people also wrinkle their noses at using virtualenv or venv because each virtual environment is its own little copy of the Python runtime, taking up about 25MB.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |