ubuntu linux下使用vscode切换python虚拟环境
生活随笔
收集整理的這篇文章主要介紹了
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虚拟环境的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python2.7删除所有非utf-8编
- 下一篇: Sqlite3 for Linux 可视