简体   繁体   English

Python 解释器(VScode)“激活”一个 conda 环境,但环境没有改变

[英]Python interpreter (VScode) "activates" a conda environment, but the environment doesn't change

I'm a bit new to Python, and I was trying to run a project in a different conda environment.我对 Python 有点陌生,我试图在不同的 conda 环境中运行一个项目。 I wanted the program to automatically run in the new conda environment that I created ("mySchedule"), instead of manually typing "conda activate mySchedule" every time.我希望程序在我创建的新 conda 环境(“mySchedule”)中自动运行,而不是每次都手动输入“conda activate mySchedule”。 So I followed VScode's instructions and used a python interpreter.所以我按照 VScode 的说明使用了 python 解释器。 I applied a python interpreter to my program folder and workspace, but there's a problem:我将 python 解释器应用到我的程序文件夹和工作区,但是有一个问题:

As in the text below (which is a result of running the program ONCE), it DOES run "conda activate mySchedule" (but does not include the '(base) name@name-MacBook..."). However, the "mySchedule" environment is NOT activated, since the environment stays as "base". Because it wasn't activated, the program ends up running in the "base" environment, which does not include the packages I'm using for the program.如下文所示(这是运行程序 ONCE 的结果),它确实运行“conda activate mySchedule”(但不包括“(基本)名称@name-MacBook ...”)。但是,“ mySchedule”环境没有被激活,因为环境保持为“基础”。因为它没有被激活,程序最终在“基础”环境中运行,其中不包括我用于程序的包。

After the program shoots out errors, the python interpreter runs "conda activate mySchedule" again (but this time with the "(base) name@name-...").程序发出错误后,python 解释器再次运行“conda activate mySchedule”(但这次使用“(base) name@name-...”)。 This activation WORKS, but it only activates at the very end, which is pretty useless.此激活有效,但它仅在最后激活,这是非常没用的。

python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py"
source /Users/name/opt/miniconda3/bin/activate

conda activate mySchedule

(base) name@name-MacBook-Air program % python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py"

<bunch of errors because the program uses packages/modules that only exist in the "mySchedule" environment, but not in the "base" environment.>

(base) name@name-MacBook-Air program % source /Users/name/opt/miniconda3/bin/activate

(base) name@name-MacBook-Air program % conda activate mySchedule

(mySchedule) name@name-MacBook-Air program % 

Does anyone have any advice on how to activate my "mySchedule" conda environment at the BEGINNING of the run?有人对如何在运行开始时激活我的“mySchedule”conda 环境有任何建议吗? Also, I've seen some solutions that make my "mySchedule" environment as the default environment, but it would be great if I didn't have to do this.此外,我还看到了一些将我的“mySchedule”环境作为默认环境的解决方案,但如果我不必这样做,那就太好了。

Maybe: Would a problem arise because I applied the python interpreter to both the program folder and the workspace?也许:是否会因为我将 python 解释器应用于程序文件夹和工作区而出现问题?

python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py" source /Users/name/opt/miniconda3/bin/activate python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py" source /Users/name/opt/miniconda3/bin/activate

conda activate mySchedule conda 激活 mySchedule

(base) name@name-MacBook-Air program % python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py" (base) name@name-MacBook-Air 程序 % python -u "/Users/name/Desktop/Desktop Organizer/Education/Coding/Schedule/program/python/Test.py"

When you run the command conda activate mySchedule , it seems that base has not been started correctly, which is equivalent to entering an invalid command, because there is no basic information of base before the command you enter.当你运行命令conda activate mySchedule时,似乎 base 没有正确启动,相当于输入了一个无效命令,因为在你输入的命令之前没有 base 的基本信息。

I wanted the program to automatically run in the new conda environment that I created ("mySchedule"),我希望程序在我创建的新 conda 环境(“mySchedule”)中自动运行,

You can manually specify the Python interpreter by adding the following code to the setting.json file:您可以通过将以下代码添加到setting.json文件来手动指定 Python 解释器:

For example,例如,

{
  "python.defaultInterpreterPath": "c:/dev/ala/venv/Scripts/python.exe"
}

You can refer to the document for more information.您可以参考文档以获取更多信息。

暂无
暂无

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

相关问题 VSCode集成终端不使用Conda环境执行python文件 - VSCode integrated terminal doesn't use Conda environment to execute python files Python解释器在Conda环境中,但是该环境没有被激活 - Python interpreter is in a Conda environment, but the environment has not been activated Windows CMD:“这个Python解释器在conda环境中,但是环境还没有激活” - Windows CMD: "This Python interpreter is in a conda environment, but the environment has not been activated" 警告“此 Python 解释器处于 conda 环境中,但该环境尚未激活” - Warning "This Python interpreter is in a conda environment, but the environment has not been activated" 这个Python解释器在conda环境下,但是环境还没有激活 - This Python interpreter is in a conda environment, but the environment has not been activated Python Anaconda解释器在conda环境下,但是环境没有激活 - Python Anaconda interpreter is in a conda environment, but the environment has not been activated cmd警告:python解释器在conda环境中,但是环境没有被激活 - cmd warning: python interpreter is in a conda environment, but the environment has not been activated 在 VSCode 中从 conda 环境导入 python package - Importing python package from conda environment in VSCode VSCode 不再识别我的 Python Conda 环境 - VSCode no Longer Recognises my Python Conda Environment conda 环境中的屏幕不使用 python PATH - Screen inside conda environment doesn't use python PATH
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM