Virtual Environment Overview for Python

I read in a virtual environment and this seems like a very useful tool, but now I am wondering how I set up my entire python environment. Now all the modules and packages that I installed are in this directory:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages 

But virtual documents seem to suggest that such a universal installation of the system is bad. If so, what should I do with my current modules and how do I install future modules? For example, I recently installed a USB flash drive from my user directory using this command:

 pip install flask 

Now it is in site packages. Should I do something else? I am having problems with the documentation, which seems to suggest that I need to go to the project directory, configure the virtual environment, and install all the modules I need using virtualenv. This is true? Is there a way to make things less bulky? It seems that installing potentially dozens of packages for each project directory will be a bit.

Or is it that I need to create virtual environments only for projects that use older versions of modules than those that I installed in the system directory? However, if so, then what about the virtual mantra, which seems to hinder the installation of the entire system?

+8
python unix virtualenv
source share
2 answers

If you have already installed virtualenv as follows:

 pip install virtualenv 

Then you want to configure a specific virtualenv folder:

 virtualenv [your project folder name] 

This will create this project folder with several important subdirectories.

First, you activate your virtual server before installing anything new, the newly installed modules will be available to you only if you are "connected" to your virtual computer. In your project folder:

 source bin/activate 

You will then see your virtualenv name in brackets on each end line. This means that you are 'sourced' in. NOW install stuff with pip or easy_install.

 pip install flask 

virtualenv basically sets your search path in the [venv folder] / bin for executables instead of / usr / local / bin or whatever. Thus, you can copy files directly to the virtual env bin folder. (MongoDB files, for example, are included in the zip / tar file, you can simply unzip them to your folder in venv bin, and you will have access to this particular version of MongoDB when there is a "source".) Try it yourself, run this command from your virtual and then standard by default to see how it changes.

 echo $PATH && echo $PYTHONPATH 

To exit your virtualenv:

 deactivate 

By entering this, you will be returned to your default environment.

If you have not read this yet, this is a pretty good resource.

https://python-guide.readthedocs.org/en/latest/dev/virtualenvs/

+13
source share

Before you put / support anything in production, you get minimal benefits from virtualenv. This is just an extra step to activate virtualenv, and of course you must set up a standard environment in each virtual space. Actually this is not so much extra effort ...

However, if you put something into production, this is a potentially great victory when everything comes at night :-)

0
source share

All Articles