简体   繁体   English

VSCode集成终端不使用Conda环境执行python文件

[英]VSCode integrated terminal doesn't use Conda environment to execute python files

[Mac OS] Up until yesterday, my python files were executing with whatever environment I had activated. [Mac OS] 直到昨天,我的 python 文件都在我激活的任何环境中执行。 After that, I explored python debugging and how it could be used with the Conda environment.之后,我探索了 python 调试以及如何将其与 Conda 环境一起使用。 It worked like a charm.它就像一个魅力。

Today, I got a notification in VSC saying something along the lines of "python.PythonPath in settings.json ... default...".今天,我在 VSC 中收到一条通知,上面说的是“settings.json 中的 python.PythonPath ... 默认...”。 Because I was in a hurry, I didn't pay attention to it.因为赶时间,所以没注意。 Now, when I activate conda environment X, it shows up in the terminal that X is activated, when I use "conda list" it lists the correct modules installed in X, and in VSC's status bar, it shows that I am using X too.现在,当我激活 conda 环境 X 时,它会在终端中显示 X 已激活,当我使用“conda list”时,它会列出 X 中安装的正确模块,并且在 VSC 的状态栏中,它显示我也在使用 X .

Unfortunately, when I go running the python code, it simply uses "python - u ", and that does not happen to be X.不幸的是,当我运行 python 代码时,它只是使用“python - u”,而这恰好不是 X。

Could someone please tell me what's wrong?有人可以告诉我出了什么问题吗? If there's some information that I haven't provided, please feel free to let me know about it and I'll update the question accordingly.如果有一些我没有提供的信息,请随时告诉我,我会相应地更新问题。

You can modify settings.json to use the specific conda environment python interpreter.您可以修改 settings.json 以使用特定的 conda 环境 python 解释器。 Or you can set the interpreter manually.或者您可以手动设置解释器。 \\ \\

Writing settings.json :编写 settings.json
add the line in settings.json :settings.json 中添加一行:

"python.pythonPath": "/home/python36/python", // the path of python 
// interpreter in your desired conda environment.

Or In the editor to the bottom left corner, you should see something like below或者在左下角的编辑器中,您应该会看到如下所示的内容编辑
Click it, you should see a prompt opening above, like单击它,您应该会看到上面的提示打开,例如在此处输入图片说明
Select the interpreter and you're good to go.选择口译员,一切顺利。

Do you mean the VSCode works like the first picture and you want it can run in the terminal like the second picture?你的意思是 VSCode 像第一张图一样工作,你想让它像第二张图一样在终端中运行吗?

在此处输入图片说明

在此处输入图片说明

The first picture was running by Code Runner , the second picture was running by Python Extension .第一张图片由Code Runner运行,第二张图片由Python Extension运行。 You can choose it like this:你可以这样选择:

在此处输入图片说明

If I am misunderstanding your problem, please point it out and provide the related info.如果我误解了您的问题,请指出并提供相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM