jeeyong
V2EX  ›  Python

[求助]sublime3 + anaconda + virtualenv 的正确姿势

By jeeyong at 2020 年 10 月 3 日 · 3591 次点击

安装配置了 sublime text 3 的 python 开发环境. 想通过 virtualenv 隔离各个项目. 现在的配置: Sublime Text3 Anaconda Virtualenv

问题: Anaconda 的 python 路径如果设置成 python.exe, 使用默认路径. 那么激活虚拟环境后, 代码提示的时候不能够提示虚拟环境中安装的库. 只能提示默认路径中安装的库. 所以应该如何正确配置 Sublime+Virtualenv+Anaconda 呢?

需求: 想要在切换虚拟环境后, 也可以正确提示该环境中安装的库.

尝试过每次修改 Anaconda Settings 中的

"python_interpreter": "python"

可以正确提示, 但这个方法太繁琐了, 每次切换项目都要重新设置吗?

希望有经验的朋友指点一下.

第 1 条附言  ·  2020 年 10 月 3 日

@ruanimal

{
    "settings":
    {
        // 虚拟环境中 Python的路径
        "python_interpreter": "D:\\coding\\web\\Scripts\\python.exe",
       // 虚拟环境site-package路径. 我感觉好像设置后稍微会提高代码提示的响应速度.
        "extra_paths":
        [
            "D:\\coding\\web\\Lib\\site-packages"
        ]
    },
    "build_systems":
    [
        {
            "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
            "name": "Anaconda Python Builder",
            "selector": "source.python",
            "shell_cmd": "\"D:\\coding\\web\\Scripts\\python.exe\" -u \"$file\""
        }
    ],
    "folders":
    [
        {
            // "follow_symlinks": true,
            "path": "."
        }
    ],
    "virtualenv": "D:\\coding\\web"
}

这样貌似就可以正常使用了. 刚配置完, 还没做更多的测试.. 之前可能因为安装和删除的插件太多, 代码提示会卡..重新装了一遍好了.

我去读了一遍Anaconda的配置文件说明. http://damnwidget.github.io/anaconda/anaconda_settings/#python-interpreter-settings

14 条回复  •  2020-10-03 21:13:21 +08:00
ljpCN
   1
ljpCN  
   2020 年 10 月 3 日   ❤️ 1
pycharm,vscode 欢迎你。
jeeyong
   2
jeeyong  
OP
   2020 年 10 月 3 日   ❤️ 1
@ljpCN 觉得 sublime 方便, 启动快, 执行快, 而且坦白的说,vscode 我也弄不明白..
ljpCN
   3
ljpCN  
   2020 年 10 月 3 日
@jeeyong [VSCode 切换 python 环境]( https://code.visualstudio.com/docs/python/environments)鼠标点点就可以,貌似安装 python 插件后它可以识别到项目下的环境并询问你是否使用。Sublime 貌似装个 conda 的插件可行,你试试:[文档]( https://docs.anaconda.com/anaconda/user-guide/tasks/integration/sublime/)
ljpCN
   5
ljpCN  
   2020 年 10 月 3 日
@ljpCN 醉了。。。请教一下 v 站发外链的正确姿势?
jeeyong
   6
jeeyong  
OP
   2020 年 10 月 3 日
@ljpCN 好嘛..我感觉你这是给我引导另一个体系去了....
我试着研究一下
jeeyong
   7
jeeyong  
OP
   2020 年 10 月 3 日
@ljpCN 我都是
```+语言或者配置文件, 再```结束

貌似不能直接点击噢
ruanimal
   8
ruanimal  
   2020 年 10 月 3 日
Anaconda 可以改全局配置
jeeyong
   9
jeeyong  
OP
   2020 年 10 月 3 日
@ruanimal


```Config
{
"settings":
{
// 虚拟环境中 Python 的路径
"python_interpreter": "D:\\coding\\web\\Scripts\\python.exe",
// 虚拟环境 site-package 路径. 我感觉好像设置后稍微会提高代码提示的响应速度.
"extra_paths":
[
"D:\\coding\\web\\Lib\\site-packages"
]
},
"build_systems":
[
{
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"name": "Anaconda Python Builder",
"selector": "source.python",
"shell_cmd": "\"D:\\coding\\web\\Scripts\\python.exe\" -u \"$file\""
}
],
"folders":
[
{
// "follow_symlinks": true,
"path": "."
}
],
"virtualenv": "D:\\coding\\web"
}
```

这样貌似就可以正常使用了.
刚配置完, 还没做更多的测试..
之前可能因为安装和删除的插件太多, 代码提示会卡..重新装了一遍好了.

我去读了一遍 Anaconda 的配置文件说明.
[url]http://damnwidget.github.io/anaconda/anaconda_settings/#python-interpreter-settings[/url]
marczhao
   10
marczhao  
   2020 年 10 月 3 日
![PyCharm with Conda]( https://imgur.com/a/i7gplRH)

个人感觉这个还是 PyCharm 方便吧?
wolfan
   11
wolfan  
   2020 年 10 月 3 日
sublime 都好像很久没更新了的样,好似自打 vscode 出来后就不怎么更新了。大约是用户断崖式的掉了一波后维护力度就降下来了吧。
zackwu
   12
zackwu  
   2020 年 10 月 3 日
Huelse
   13
Huelse  
   2020 年 10 月 3 日
建议放弃 sublime3,这玩意连中文字符集都没有,导致看某些老文件直接注解乱码。。。
wangkun025
   14
wangkun025  
   2020 年 10 月 3 日
@Huelse 比如?给个文件我看看。多谢。
推荐学习书目
› 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
© 2026 V2EX · 37ms · 3.9.8.5