推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
luis330
V2EX  ›  Python

如何让 VS Code 使用 virtualenv 里的 python 环境

  •  
  •   luis330 · Apr 15, 2016 · 23796 views
    This topic created in 3725 days ago, the information mentioned may be changed or developed.

    新手小白向给位朋友请教,在配置好并启动 virtualenv 环境后,如何让 VS Code 使用这个环境下来编译调试 python 脚本呢? VS Code 今天刚拿下来, 1.0 版,还很不熟悉!谢谢!

    10 replies    2018-03-10 09:30:56 +08:00
    rwecho
        1
    rwecho  
       Apr 15, 2016
    我也没用,运行的时候还是用的命令行
    kungfuchicken
        2
    kungfuchicken  
       Apr 15, 2016
    luis330
        3
    luis330  
    OP
       Apr 18, 2016
    @kungfuchicken 感谢了,这个已经装了,我问的不是 python debug ,我想要 VS Code 能在 virtualenv 环境下 debug
    kungfuchicken
        4
    kungfuchicken  
       Apr 18, 2016
    @luis330 你配置下这个工具,使用你 virtualenv 下的 python 来运行就能 debug 呀
    luis330
        5
    luis330  
    OP
       Apr 18, 2016
    @kungfuchicken 感谢提醒,折腾了一下,在项目的\.vscode\launch.json 文件里加了一句:
    "pythonPath": "D:\\myproject\\venv\\Scripts\\python.exe",
    这下就不影响全局了。
    testcgd
        6
    testcgd  
       Jun 3, 2016
    我在 ubuntu 下解决方案是先 source ./bin/actiate 进入到虚拟的环境后再在命令行中启动 vscode,可以作为一个参考
    asuraa
        7
    asuraa  
       Jul 18, 2017   ❤️ 2
    使用命令行 ctrl +p 然后输入 python:select wordspace interpreter
    mgr1979
        8
    mgr1979  
       Sep 7, 2017
    如何让 VS Code 使用 virtualenv 里的 python 环境 到底怎么才能做到?有类似 PyCharm 那样方便的么?
    lukic
        9
    lukic  
       Oct 30, 2017
    @luodaoyi 正解。
    shenjian74
        10
    shenjian74  
       Mar 10, 2018
    假设所有的 venv 都放在 d:\envs 目录下,设置下面两个配置项:
    "python.venvPath": "D:\\envs",
    "python.venvFolders": [
    "envs",
    ".pyenv",
    ".direnv"
    ],

    然后运行命令 Python: Select Interpreter 就可以选择 venv 了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2928 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 03:27 · PVG 11:27 · LAX 20:27 · JFK 23:27
    ♥ Do have faith in what you're doing.