程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python open virtual environment

編輯:Python

What is a virtual environment

Installing python is equivalent to installing a global environment.However, when the application is developed and used, I want to have an isolation to avoid the influence of other applications.So, Python uses virtual environments.The virtual environment is equivalent to a copy of the Python native environment. The standard library used is the same, and each copy will cause a lot of redundancy.Therefore, the Python virtual environment directly calls the native standard library.

Use of virtual environment

Create a virtual environment

python(python3) -m venv [name of virtual environment] Create a virtual environment in the current directoryEnvironment

Enter the virtual environment

cd [Virtual environment name directory]/bin Enter the virtual environment directory in the current directory source activate Activate the current virtual environment

Exit the virtual environment

deactivate Exit the current virtual environment

Importance of the virtual environment

  • IfTo do a lot of tasks in an environment, you need to install many third-party packages. Sometimes there will be version incompatibility between third-party packages and packages, resulting in unavailability; and it is difficult to manage an environment when there are too many packages.If we restrict each task to operate in a virtual environment and install only the packages required by this task, the probability of incompatibility problems will be greatly reduced.
  • You can configure the running environment of other people's projects directly through the virtual environment, so that you can run other people's code.

Save the virtual environment

During the development of Python projects, third-party libraries are usually used.It can be executed directly in the virtual environment: pip freeze > requirements.txt Freeze the library of the virtual environment and save it to the requirements.txt file.In this way, the application environment can be built at any time anywhere.
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved