亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

VSCode配合pipenv搞定虛擬環(huán)境的實(shí)現(xiàn)方法

 更新時(shí)間:2020年05月17日 10:01:35   作者:Rainbird的個(gè)人博客  
這篇文章主要介紹了VSCode配合pipenv搞定虛擬環(huán)境的實(shí)現(xiàn)方法,文中通過圖文教程介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

VSCode指定Python路徑快捷運(yùn)行py腳本之前寫過了,這樣配置有一個(gè)問題:所有的python腳本都使用的同一個(gè)python來執(zhí)行的.現(xiàn)在是虛擬環(huán)境的天下,怎樣做到不同的項(xiàng)目使用的不同的Python環(huán)境呢?

想做到這個(gè)也簡單,關(guān)鍵三點(diǎn)

一.使用不同的VSCode打開不同的項(xiàng)目

二.虛擬環(huán)境以同樣的文件夾名放在項(xiàng)目根目錄如.venv

三.之前的python路徑設(shè)置相對(duì)路徑 .venv/bin/python

預(yù)期目標(biāo)兩個(gè):

一 使用Command+Shift+b運(yùn)行時(shí)使用當(dāng)前虛擬環(huán)境的python

二 py文件右鍵 在終端中打開Open in Integrated Terminal 時(shí)自動(dòng)激活當(dāng)前虛擬環(huán)境

因?yàn)楣P者鐘愛pipenv所以就以它創(chuàng)建虛擬環(huán)境演示了.

創(chuàng)建項(xiàng)目并將虛擬環(huán)境放在.venv

➜ Desktop mkdir c_test_py
➜ Desktop cd c_test_py
➜ c_test_py mkdir .venv
➜ c_test_py pipenv --python 3.8.2
Creating a virtualenv for this project...
Pipfile: /Users/rainbird/Desktop/c_test_py/Pipfile
Using /Users/rainbird/.pyenv/versions/3.8.2/bin/python (3.8.2) to create virtualenv...
⠸ Creating virtual environment...Already using interpreter /Users/rainbird/.pyenv/versions/3.8.2/bin/python
Using base prefix '/Users/rainbird/.pyenv/versions/3.8.2'
New python executable in /Users/rainbird/Desktop/c_test_py/.venv/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Users/rainbird/.pyenv/versions/3.8.2/bin/python

✔ Successfully created virtual environment!
Virtualenv location: /Users/rainbird/Desktop/c_test_py/.venv
Creating a Pipfile for this project...
➜ c_test_py pipenv shell
Launching subshell in virtual environment...
 . /Users/rainbird/Desktop/c_test_py/.venv/bin/activate
➜ c_test_py . /Users/rainbird/Desktop/c_test_py/.venv/bin/activate
(c_test_py) ➜ c_test_py python -V
Python 3.8.2
(c_test_py) ➜ c_test_py

通過上面可以看到,我們最后一個(gè)pipenv shell成功激活了當(dāng)前目錄下的.venv的虛擬環(huán)境

VSCode新建窗口打開新工程

或者直接將新創(chuàng)建c_test_py文件件拖到新容器也可以.

配置python路徑為相對(duì)路徑

VSCode菜單-終端->配置任務(wù)

將之前的絕對(duì)路徑改成相對(duì)路徑 .venv/bin/python

{
 // See https://go.microsoft.com/fwlink/?LinkId=733558
 // for the documentation about the tasks.json format
 "version": "2.0.0",
 "tasks": [
  {
   //command + shift + b 運(yùn)行時(shí)使用
   "label": "python",
   "type": "shell",
   "command": ".venv/bin/python",
   "args": [
    "${file}"
   ],
   "group": {
    "kind": "build",
    "isDefault": true
   }
  }
 ]
}

驗(yàn)證

在新開的文件夾里新建index.py并輸出hello world

print('hello world !')

通過command+shift+b運(yùn)行發(fā)現(xiàn)已經(jīng)是使用的相對(duì)路徑了.

在index.py上右鍵選擇 在終端中打開

也自動(dòng)激活了當(dāng)前虛擬環(huán)境,完美!!!

到此這篇關(guān)于VSCode配合pipenv搞定虛擬環(huán)境的實(shí)現(xiàn)方法的文章就介紹到這了,更多相關(guān)VSCode pipenv虛擬環(huán)境內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論