使用批处理文件在 Anaconda 中激活 python 3 环境 [英] Activate python 3 environemnt in Anaconda with batch-file
问题描述
最近在win7上为我的python项目安装了Anaconda (1.9)
Recently installed Anaconda (1.9) for my python project on win7
安装后,我在这个页面中建立了一个python 3支持环境.我的下一个任务是使用内置批处理文件自动激活我的 python 环境.
After installation, I built a python 3 support environment with instruction in this page. My next task is to activate my python environment automatically with built-in batch file.
我使用了在开始菜单中找到的 [Anaconda 命令提示符] 快捷方式中的命令.它运行一个名为 [anaconda.bat]
I used the command in [Anaconda Command Prompt] shortcut I found in my start menu. It runs a batch-file called [anaconda.bat]
观察批处理文件后,我意识到它似乎能够接受一个输入参数,该参数应该是我想要激活的环境.所以我复制了快捷方式并将其修改为
After observing the batch file I realized it seems to be capable of taking an input argument that is supposed to be the environment I would like to activate. So I copied the shortcut and modified it as
C:WindowsSystem32cmd.exe /k "C:AnacondaScriptsanaconda.bat py3k"
然后我双击新的快捷方式,它打开了一个新的命令窗口,但是……指定的环境没有激活!
Then I double clicked on the new shortcut, it opened a new command window but...the designated environment did not activate!
@echo off
rem +===========================================================================
rem | Initialisation
rem +===========================================================================
verify bogus-argument 2>nul
setlocal enableextensions enabledelayedexpansion
if ERRORLEVEL 1 (
echo error: unable to enable command extensions
goto :eof
)
for %%i in ("%~dp0..envs") do (
set ANACONDA_ENVS=%%~fi
)
if not "%1" == "" (
if not exist "%ANACONDA_ENVS%\%1python.exe" (
echo No environment named "%1" exists in %ANACONDA_ENVS%
goto :eof
)
set ANACONDA_ENV_NAME=%1
set ANACONDA=%ANACONDA_ENVS%\%1
title Anaconda (%ANACONDA_ENV_NAME%^)
) else (
set ANACONDA_ENV_NAME=
for %%i in ("%~dp0..") do (
set ANACONDA=%%~fi
)
title Anaconda
)
set ANACONDA_SCRIPTS=%ANACONDA%Scripts
for %%i in ("python.exe") do (
for %%j in ("%ANACONDA%python.exe") do (
if not "%%~f$PATH:i" == "%%~f$PATH:j" (
set ANACONDA_OLD_PATH="%PATH%"
set PATH=%ANACONDA%;%ANACONDA_SCRIPTS%;%PATH%;
echo Added %ANACONDA% and %ANACONDA_SCRIPTS% to PATH.
)
)
)
if not "%ANACONDA_ENV_NAME%" == "" (
echo Activating environment %ANACONDA_ENV_NAME%...
set PROMPT=[%ANACONDA_ENV_NAME%] $P$G
)
我对蝙蝠语言的经验很少,但我想这行可能与此有关
I have very little experience with bat language but I guess there may be something to do with this line
setlocal enableextensions enabledelayedexpansion
我试图删除该行,但一直被困在带有消息的 ERRORLEVEL 1 表达式中.
I tried to remove that line but kept trapped in the ERRORLEVEL 1 expression with message.
error: unable to enable command extensions
谁能建议我应该怎么做才能使这个 bat 文件正常工作?
Can anyone suggest what I should do to make this bat-file work properly?
推荐答案
我认为你不需要批处理文件.假设 Anaconda 和 CMD 在你的路径上(它们应该是),你可以试试这个作为替代方法(这就是我所做的):
I don't think you need a batch file. Assuming that Anaconda and CMD are on your path (which they should be), you can try this as an alternative (it is what I do):
cmd "/c activate py3k && ipython --pylab"
这篇关于使用批处理文件在 Anaconda 中激活 python 3 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!