在macOS下正確配置 VS Code 使用 virtualenv 里的 python 環境參數


在macos配置好並啟動 virtualenv 環境后,如何讓 VS Code 使用這個環境下來編譯調試 python 腳本呢?

 

1.首先當然是先配置好python虛擬環境

 假定配置python的的虛擬路徑如下:

  $HOME\xxx\env

  ps2

     ps35

     ps36

2.然后在vscode的工作區設置中設置如下兩個配置項:

{
    "folders": [
        {
            "path": "demo"
        }
    ],
    "settings": {
        "python.pythonPath": "/Users/xxx/env/ps36/bin/python",
         "python.venvPath": "/Users/xxx/env",
        "python.venvFolders": [
            "ps2",
            "ps35",
            "ps36"
        ]

    }
}
3.重新啟動vs code,然后打開python工作區,然后cmd+shift+p然后輸入選擇Python: Select Interpreter 就可以選擇 venv 了。
 

python虛擬環境virtualenv的安裝與使用


virtualenvwrapper的安裝及使用


 

virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv

tool.  The extensions include wrappers for creating and deleting

virtual environments and otherwise managing your development workflow,

making it easier to work on more than one project at a time without

introducing conflicts in their dependencies.

 

For more information please refer to the documentation:

 

    http://virtualenvwrapper.readthedocs.org/en/latest/command_ref.html

 

Commands available:

 

  add2virtualenv: add directory to the import path

 

  allvirtualenv: run a command in all virtualenvs

 

  cdproject: change directory to the active project

 

  cdsitepackages: change to the site-packages directory

 

  cdvirtualenv: change to the $VIRTUAL_ENV directory

 

  cpvirtualenv: duplicate the named virtualenv to make a new one

 

  lssitepackages: list contents of the site-packages directory

 

  lsvirtualenv: list virtualenvs

 

  mkproject: create a new project directory and its associated virtualenv

 

  mktmpenv: create a temporary virtualenv

 

  mkvirtualenv: Create a new virtualenv in $WORKON_HOME

 

  rmvirtualenv: Remove a virtualenv

 

  setvirtualenvproject: associate a project directory with a virtualenv

 

  showvirtualenv: show details of a single virtualenv

 

  toggleglobalsitepackages: turn access to global site-packages on/off

 

  virtualenvwrapper: show this help message

 

  wipeenv: remove all packages installed in the current virtualenv

 

  workon: list or change working virtualenvs

 

mkvirtualenv創建python虛擬環境

mkvirtualenv -p <指定版本python可執行文件名>  <虛擬環境目錄名>

 比如:
使用python2.7
mkvirtualenv -p python2.7  py27
  使用python3.7
mkvirtualenv -p python3.7  py37
 
 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM