日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

ubuntu linux下使用vscode切换python虚拟环境

發布時間:2023/12/20 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu linux下使用vscode切换python虚拟环境 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

VSCODE的桌面腳本是:

[Desktop Entry] Version=1.0 Type=Application Name=VSCODE Comment= Exec=/home/appleyuchi/下載/VSCode-linux-x64/bin/code Icon=/home/appleyuchi/下載/VSCode-linux-x64/resources/app/resources/linux/code.png Terminal=false StartupNotify=false

?

請注意本文的討論環境:

Ubuntu Linux 16.04 64位

在打開軟件后,不關閉軟件的情況下,切換python虛擬環境,使用的驗證代碼是:

import sys print(sys.prefix) print(sys.executable)

?

第一步:按下左邊的紙張圖標

?

第二步:選擇launch.json

?

第三步,launch.json的內容如下:

{"version": "0.2.0","configurations": [{"name": "Python","type": "python","request": "launch","stopOnEntry": true,// "pythonPath": "${config:python.pythonPath}","pythonPath": "${config:python.pythonPath}",// "pythonPath": "${config:python.pythonPath}","program": "${file}","cwd": "${workspaceRoot}","env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "PySpark","type": "python","request": "launch","stopOnEntry": true,"osx": {"pythonPath": "${env:SPARK_HOME}/bin/spark-submit"},"windows": {"pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd"},"linux": {"pythonPath": "${env:SPARK_HOME}/bin/spark-submit"},"program": "${file}","cwd": "${workspaceRoot}","env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "Python Module","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","module": "module.name","cwd": "${workspaceRoot}","env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "Integrated Terminal/Console","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","program": "${file}","cwd": "","console": "integratedTerminal","env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit"]},{"name": "External Terminal/Console","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","program": "${file}","cwd": "","console": "externalTerminal","env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit"]},{"name": "Django","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","program": "${workspaceRoot}/manage.py","cwd": "${workspaceRoot}","args": ["runserver","--noreload","--nothreading"],"env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput","DjangoDebugging"]},{"name": "Flask","type": "python","request": "launch","stopOnEntry": false,"pythonPath": "${config:python.pythonPath}","program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter","cwd": "${workspaceRoot}","env": {"FLASK_APP": "${workspaceRoot}/quickstart/app.py"},"args": ["run","--no-debugger","--no-reload"],"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "Flask (old)","type": "python","request": "launch","stopOnEntry": false,"pythonPath": "${config:python.pythonPath}","program": "${workspaceRoot}/run.py","cwd": "${workspaceRoot}","args": [],"env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "Pyramid","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","cwd": "${workspaceRoot}","env": {},"envFile": "${workspaceRoot}/.env","args": ["${workspaceRoot}/development.ini"],"debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput","Pyramid"]},{"name": "Watson","type": "python","request": "launch","stopOnEntry": true,"pythonPath": "${config:python.pythonPath}","program": "${workspaceRoot}/console.py","cwd": "${workspaceRoot}","args": ["dev","runserver","--noreload=True"],"env": {},"envFile": "${workspaceRoot}/.env","debugOptions": ["WaitOnAbnormalExit","WaitOnNormalExit","RedirectOutput"]},{"name": "Attach (Remote Debug)","type": "python","request": "attach","localRoot": "${workspaceRoot}","remoteRoot": "${workspaceRoot}","port": 3000,"secret": "my_secret","host": "localhost"}] }

注意上面的重點是所有的pythonPath的值都必須是下面這個

?

"pythonPath": "${config:python.pythonPath}"

或者刪除launch.json,然后重新啟動讓他自己建立。

第四步,vscode內部切換虛擬環境方法(注意,如果沒有以上的設置,下面的虛擬環境切換操作很可能會失效。):

下面是我向作者請教的過程:

https://github.com/Microsoft/vscode-python/issues/173#issuecomment-364661275

總結

以上是生活随笔為你收集整理的ubuntu linux下使用vscode切换python虚拟环境的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。