V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2016-04-15 16:27:50 +08:00 · 22723 次点击
    这是一个创建于 2930 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    然后运行命令 Python: Select Interpreter 就可以选择 venv 了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5835 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 02:58 · PVG 10:58 · LAX 19:58 · JFK 22:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.