如何在 Python 脚本中激活 Anaconda 环境?

2022-01-10 00:00:00 python anaconda

问题描述

我已经搜索过堆栈溢出,但没有任何帖子专门针对 Anaconda 提供帮助.

I have searched through stack overflow, but no post helped specifically with Anaconda.

我正在尝试在 Python 中使用我自己的命令行提示符.但要做到这一点,我需要激活我的 Anaconda 环境.我在网络上的任何地方都找不到如何运行基本的 python 脚本来激活所述环境.有谁知道怎么做?

I am trying to my own Command line prompt in Python. But to do that, I need to activate my Anaconda environment. I cant find anywhere on the web how to run a basic python script to be able to activate said environment. Does anyone know how to do so?


解决方案

您应该能够使用命令行来激活特定环境,只需键入:

You should be able to use the command line to activate specific environments just by typing:

activate environment-name

您必须在 Linux 上使用源代码.

You will have to do use source on Linux.

source activate environment-name

http://conda.pydata.org/docs/using/envs.html#change-environments-activate-deactivate

编辑(2016 年 3 月 29 日)

对不起,我误读了这个问题.您应该可以使用 subprocess 模块 中的 call 方法来运行 shell通过 Python 脚本命令.

Sorry, I misread the question. You should be able to use the call method in the subprocess module to run the shell command through a Python script.

子流程的基本示例:

subprocess.call(["activate", value])

相关文章