What can happen to my project if I remove the virtual environment set up for it?

Asked

Viewed 669 times

2

Let’s say I created a virtual environment through virtualenvwrapper $ mkvirtualenv venv. I create my project, make the necessary settings, start working on the project and one fine day I do the removal of the virtual environment $ rmvirtualenv venv.

What are the effects that could happen in my project?

  • If your project is not active nothing will happen, but it is interesting you save in a file all the packages installed in this virtual environment, for this use pip freeze > requirements.txt

  • I could start a new virtual environment from Requirements.txt?

  • After recreating the environment just use the command pip install requirements.txt and all packages required by the project will be installed.

  • Missed the -r: pip install -r requirements.txt

  • Very good, man! It was worth too much.

1 answer

0


The idea of a virtual environment is precisely to provide an environment for your project, however redundant it may seem. That is, as long as you know how to set up an environment for your project, it doesn’t matter if you delete the environment you’re working in. In fact, you can even recreate this environment on another machine (for example on a remote server) that your project will work on.

However, keeping all your project’s settings (and possibly several others) in mind is somewhat problematic. You may forget some specific dependency and face enough difficulty to recreate your environment. To do so, it is common to save together with your project a list of the packages it depends on. You can create this list using Pip:

pip freeze > dependencias.txt

If you take a look at the generated file, you will see that, in addition to the package names, their respective versions are also included. Because of this, it is advisable that you include this file in your version control system.

With this, if you unintentionally delete your virtual environment, or need to run your project on another machine, just install the packages contained in this list. Again, Pip has a command for this. After creating and activating a new virtual environment, run:

pip install -r dependencias.txt

And that’s it, your project should work properly.

  • Perfect, my dear! Thank you.

  • 1

    Just remembering that it is better to use all the names in English - in the case of this file, there is even a stronger reason for the nme of it to be "Requirements.txt": several automatic systems of environment recreation, and many, ams many Python developers expect dependencies to be in a file with this name: "Requirements.txt"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.