問題描述
我已經(jīng)搜索過堆棧溢出,但沒有任何帖子專門針對 Anaconda 提供幫助.
I have searched through stack overflow, but no post helped specifically with Anaconda.
我正在嘗試在 Python 中使用我自己的命令行提示符.但要做到這一點,我需要激活我的 Anaconda 環(huán)境.我在網(wǎng)絡(luò)上的任何地方都找不到如何運行基本的 python 腳本來激活所述環(huán)境.有誰知道怎么做?
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?
推薦答案
您應(yīng)該能夠使用命令行來激活特定環(huán)境,只需鍵入:
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 日)
對不起,我誤讀了這個問題.您應(yīng)該可以使用 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])
這篇關(guān)于如何在 Python 腳本中激活 Anaconda 環(huán)境?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!