1. 程式人生 > >python虛擬環境virtualenv簡介

python虛擬環境virtualenv簡介

pytho http -- org 很多 provides cati lan 新的

參考網站: https://realpython.com/python-virtual-environments-a-primer/

一、 創建一個新的虛擬環境

# Python 2:
virtualenv my_new_virtualenv

# Python 3. Python3 already has the venv module from the standard library installed
python3 -m venv my_new_virtualenv
or
virtualenv -p $(which python3) my_new_virtualenv

啟動虛擬環境

cd ....../python-virtual-environments
source my_new_virtualenv/bin/activate

關閉虛擬環境

deactivate

二、虛擬環境的工作原理

該部分內容可以參考上述網站中的如下章節,

How Does a Virtual Environment Work?

其中最主要的內容為,在兩種環境中,python executables的存放位置 $which python 和環境變量$PATH $echo $PATH 有所不同。

三、virtualenvwrapper -- 管理多個虛擬環境的工具

當我們創建了多個虛擬環境時,圍繞了如何管理這些虛擬環境產生了很多問題,因此,python提供了一個工具包virtualenvwrapper用於管理多個虛擬環境。以下列舉該工具包的幾個實用功能,詳情請參考上述網站。

  • Organizes all of your virtual environments in one location
  • Provides methods to help you easily create, delete, and copy environments
  • Provides a single command to switch between environments

python虛擬環境virtualenv簡介