Take note updates as you learn,歡迎指正.
針對不同的任務,will be applied differently Python解釋器,Install different dependencies.Want to configure different environments on the same computer,為了方便管理,可以創建不同的虛擬環境.常用的工具包括 Anaconda 和 Virtualenv,How to use can refer to the blog post:virtualenv的介紹及基本使用(所有命令解釋)和 conda常用命令:安裝,更新,創建,激活,關閉,查看,卸載,刪除,清理,重命名,換源,問題.
This article focuses on direct usePython創建虛擬環境.
### Windows系統 ###
win + R
輸入cmd
### Linux系統 ###
Ctrl + Alt + T
在命令行中輸入Python,確定當前Python版本.
When a computer has more than one installedPython版本,在Windows系統中,默認調用 環境變量 the top onePython版本.Which one is required for a virtual environmentPython版本,Just move its environment variables to the top.
# 跳轉到目標目錄下
d:
cd d:\venv
# 創建虛擬環境
### Windows系統 ###
python -m venv 環境名稱
### Linux系統 ###
python3 -m venv 環境名稱
### Windows系統下 ###
# First jump to the environment folderScripts中
cd d:\venv\環境名稱\Scripts
# 激活當前環境
.\activate
### Linux系統下 ###
# First jump to the environment folderbin中
cd venv\環境名稱\bin
# 激活當前環境
source .\activate
The download speed of foreign sources is relatively slow,可能出現鏈接超時.It can be downloaded from domestic mirror sources.
pip install Depends on the package name -i 地址
You can also add domestic mirror sources to config
中,之後使用 pip install'
The command will be downloaded from this address first.
# 添加鏡像源
pip config set global.index-url 鏡像源地址
# 查看目前正在使用的源
pip config list
# 刪除源
pip config unset global.index-url
激活環境後,使用 pip list
You can view which packages are installed in the current environment.
VS Code 通過配置 settings.json
文件來選擇Python編譯器.詳細流程可以參考溫柔且上進c的博文.
Ctrl + Shift + P
打開命令交互面板;Python: Select Interpreter
選擇,也可以通過 settings
打開 settings.json
文件;Scripts\python.exe
添加到 python.pythonPath
中;"python.pythonPath": "D:\\venv\\環境名稱\\Scripts\\python.exe"
Pycharm It is relatively simple to directly select the virtual environment folder Scripts\python.exe
Python解釋器即可.
溫柔且上進c. 解決問題:VScode使用python虛擬環境(圖文並茂版). SCDN博客.
Drowning Yang. vscode設置Python虛擬環境. CSDN博客.