让 VSCode 使用全局 python 配置,而不是虚拟环境? [英] Make VSCode use global python config, not virtual environment?

查看:67
本文介绍了让 VSCode 使用全局 python 配置,而不是虚拟环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Visual Studio Code 来编辑 Python 程序.为了保持可移植性,我希望将 Python 程序包含在 Python 虚拟环境中.为了保持 venv 小,我只想安装 Python 程序需要的东西(特别是不安装 VSCode 需要的东西).

I'd like to use Visual Studio Code to edit a Python program. To keep it portable, I'd like the Python program to be contained in a Python virtual environment. To keep the venv small I'd like to only install those things that the Python program needs (and to specifically NOT install things that VSCode needs).

我通过在 settings.json 文件中为我的项目(即我的工作区设置,而不是我的用户设置)设置python.pythonPath"变量来告诉 VSCode 使用哪个 venv.这很好,因为我可以运行程序/调试程序.

I told VSCode which venv to use by setting the "python.pythonPath" variable in the settings.json file for my project (i.e., my Workspace Settings, not my User Settings). This works fine in the sense that I can run the program / debug the program.

VSCode 想要使用 flake8 来做一些 linting,我 100% 支持这个 - 我非常感谢 VSCode & 的 Python linting.flake8 做 :)

VSCode wants to use flake8 to do some linting, and I 100% support this - I greatly appreciate the Python linting that VSCode & flake8 do :)

然而,VSCode 通过将 flake8 库安装到我程序的虚拟环境中来实现这一点,而不是计算机范围的 Python 安装.

如何设置VSCode使用虚拟环境运行&调试程序,但将它需要的所有库(flake8、rope 等)安装到不同的/系统范围的 Python 目录中?

推荐答案

您可以手动安装 flake8 -- 例如python3 -m pip install --user flake8 在您的 venv 之外 -- 然后手动设置 您个人 settings.json 文件中 flake8 的路径.这使您可以在为您的用户帐户安装 flake8 的同时从您的 venv 运行您的代码(我们不建议全局安装).

You can do the installation of flake8 manually -- e.g. python3 -m pip install --user flake8 outside of your venv -- and then manually set the path to flake8 in your personal settings.json file. That lets you run your code from your venv while installing flake8 for your user account (we don't recommend installing globally).

这篇关于让 VSCode 使用全局 python 配置,而不是虚拟环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆