如何让 VS Code 使用 virtualenv 里的 python 环境 - V2EX
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 23444 次点击
    这是一个创建于 3534 天前的主题,其中的信息可能已经有所发展或是发生改变。

    新手小白向给位朋友请教,在配置好并启动 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     Solana     2838 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 14:16 PVG 22:16 LAX 06:16 JFK 09:16
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86