This article and everyone to share is mainly Python virtualenv and Pip of the use of related content, take a look at it, I hope you learn Python help.0x00 Installation EnvironmentWe need to use a variety of libraries in the development and learning of Python, and then the different versions that may be used in various projects and works, just because of the existence of this problem.virtualenv's birth. Virtualenv can create a virtual environment on your computer that can create a virtual environment for each project, so you don't have to worry about the conflicts that occur when different projects use different versions of the library.The following content applies only to LINUX/OSX, without testing the Windows environmentTo use this feature or to install it, the installation virtualenv must be installed directly with Pip,pip Install virtualenvYou can easily put it on. We can test a wave after it's loaded.0x01 Initializes an empty working environmentFirst, execute in an empty environmentvirtualenv--no-site-packages test_envis to create a virtual environment named Test_env in the current directory. Over here--no-site-packagesThe parameter refers to not carrying any third-party libraries from the global Python. For example, you install the XXX library in the global Python, and when you do not use this parameter to create a virtual environment, the virtual environment will also carry the library, but with this parameter, the virtual environment is a pure Python, without these libraries. Root in ~λvirtualenv--No-site-packages test_envnewpythonExecutable in/root/test_env/bin/pythonPlease MakeSure Remove anypreviousCustom Paths from Your/root/.pydistutils.cfgfile. Installing Setuptools, Pip, Wheel...done. You can thenSource Test_env/bin/activatecan enter (activate) into this virtual environment. After entering the virtual environment, usually your command prompt will be preceded by a parenthesis with the name of your virtual environment written in parentheses. This is the virtual environment, in fact, everything is real. Just say that you are activating this environment, in this environment with PIP installed libraries are placed intest_envIn You can also passDeactivateTo exit the environment.0X02 Batch export and install librariesFor example, we have developed a project that uses more than 10 20 libraries such as pymongo/requests/flask/pymysql and so on, and specifies a specific version, which can be cumbersome when migrating a project from machine A to machine B. It is cumbersome to manually record each library and version, and to install it individually. So for this problem Pip has a very complete solution. (test_env) Rootinch~λpip freeze > Requirements.txt # Export installed libraries This command exports all third-party libraries that are installed in the current environment and is exported in a standard format. So a standard Python project's root directory will have this nameRequirements.txtDependent files. Since it can be exported at once, it is necessary to install it once. In this way, all the libraries of the specific versions exported above can be loaded all at once. With Virtualenv, you can quickly deploy a Python project without messing up other Python project environments. (test_env_1) Rootinch~λpip install-r requirements.txt Source: Shawn ' s Blog
How do virtualenv and pip work in Python?