Anaconda prompt loading error: The input line is too long

Anaconda prompt loading error: The input line is too long

我在 Windows 7 64 位版本上安装了 Anaconda 64 python 2.7。 安装后anaconda提示可以启动,没有问题。但是每当我 restart/shutdown 并重新启动笔记本电脑时,anaconda 提示符会显示以下错误消息,并且某些 python 包无法加载到 jupyter notebook 中。

Deactivating environment "C:\Users\user\Anaconda2"...
Activating environment "C:\Users\user\Anaconda2"...
The input line is too long.
 "PATH_NO_SCRIPTS=C:\Users\user\Anaconda2;;C:\Users\user\Anaconda2\Lib
rary\bin;C:\Python27\;C:\Python27\Scripts;c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;
C:\ProgramData\Oracle\Java\javapath;%COSMOSM%;C:\Program Files\Lenovo Fingerprin
t Reader\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP
\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program File
s (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Man
agement Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine
Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Component
s\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\
Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon
\;C:\Program Files\Sony\VAIO Improvement\;C:\Program Files (x86)\Sony\VAIO Start
up Setting Tool;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;
c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files
 (x86)\Common Files\Roxio Shared\OEM.0\DLLShared\;c:\Program Files (x86)\Roxi
o 2010\OEM\AudioCore\;C:\Program Files (x86)\Common Files\Thunder Network\KanKan
\Codecs;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\IVI Foundat
ion\VISA\Win64\Bin\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Pro
gram Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program Files (x86)\IVI Founda
tion\IVI\bin;C:\Program Files\IVI Foundation\IVI\bin;C:\PROGRA~2\IVIFOU~1\VISA\W
inNT\Bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Python27;C:\Users\user\AppData\Local\Smartbar\Application\;C:\Program Files (x86)\WinSCP\;C:\Python
27\Scripts;C:\Program Files\ffmpeg\bin;C:\Program Files\Microsoft SQL Server0
\Tools\Binn\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files (x86
)\Windows Kits.1\Windows Performance Toolkit\;C:\HashiCorp\Vagrant\bin;C:\Prog
ram Files (x86)\Skype\Phone\;;C:\Users\user\Desktop\win64\lib;C:\Users\user\Desktop\win64\3rdparty\cudnn\bin;C:\Users\user\Desktop\win64\3rdpa
rty\cudart;C:\Users\user\Desktop\win64\3rdparty\vc;C:\Users\user\Desk
top\win64\3rdparty\openblas\bin;C:\Python27\;C:\Python27\Scripts;c:\Rtools\bin;
c:\Rtools\gcc-4.6.3\bin;C:\ProgramData\Oracle\Java\javapath;%COSMOSM%;C:\Program
 Files\Lenovo Fingerprint Reader\;C:\Program Files (x86)\Intel\iCLS Client\;C:\P
rogram Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Pro
gram Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\Syste
m32\Wbem;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Int
el(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Man
agement Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management E
ngine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Fi
les\Intel\WirelessCommon\;C:\Program Files\Sony\VAIO Improvement\;C:\Program Fil
es (x86)\Sony\VAIO Startup Setting Tool" was unexpected at this time.

我尝试遵循解决方案 here and here,但没有成功。

我查看了 Anaconda 下的 Script 文件夹,发现错误信息可能来自 activate.bat 文件。但是我不知道下一步该怎么做。

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
REM Check for CONDA_ENVS_PATH environment variable
REM It it doesn't exist, look inside the Anaconda install tree
IF "%CONDA_ENVS_PATH%" == "" (
    REM turn relative path into absolute path
    CALL :NORMALIZEPATH CONDA_ENVS_PATH "%~dp0..\envs"
)

REM Used for deactivate, to make sure we restore original state after deactivation
IF "%CONDA_PATH_BACKUP%" == "" (SET "CONDA_PATH_BACKUP=%PATH%")

set "CONDA_NEW_NAME=%~1"

IF "%~2" == "" GOTO skiptoomanyargs
    ECHO ERROR: Too many arguments provided
    GOTO usage
:skiptoomanyargs

IF "%CONDA_NEW_NAME%" == "" set "CONDA_NEW_NAME=%~dp0.."

REM Search through paths in CONDA_ENVS_PATH
REM First match will be the one used

FOR %%F IN ("%CONDA_ENVS_PATH:;=" "%") DO (
    IF EXIST "%%~F\%CONDA_NEW_NAME%\conda-meta" (
       SET "CONDA_NEW_PATH=%%~F\%CONDA_NEW_NAME%"
       GOTO found_env
    )
)

IF EXIST "%CONDA_NEW_NAME%\conda-meta" (
    SET "CONDA_NEW_PATH=%CONDA_NEW_NAME%"
    ) ELSE (
    ECHO No environment named "%CONDA_NEW_NAME%" exists in %CONDA_ENVS_PATH%, or is not a valid conda installation directory.
    EXIT /b 1
)

:found_env

SET "SCRIPT_PATH=%~dp0"
IF "%SCRIPT_PATH:~-1%"=="\" SET "SCRIPT_PATH=%SCRIPT_PATH:~0,-1%"

REM Set CONDA_NEW_NAME to the last folder name in its path
FOR /F "tokens=* delims=\" %%i IN ("%CONDA_NEW_PATH%") DO SET "CONDA_NEW_NAME=%%~ni"

REM special case for root env:
REM   Checks for Library\bin on PATH.  If exists, we have root env on PATH.
call :NORMALIZEPATH ROOT_PATH "%~dp0.."
CALL SET "PATH_NO_ROOT=%%PATH:%ROOT_PATH%;=%%"
IF NOT "%PATH_NO_ROOT%"=="%PATH%" SET "CONDA_DEFAULT_ENV=%ROOT_PATH%"

REM Deactivate a previous activation if it is live
IF "%CONDA_DEFAULT_ENV%" == "" GOTO skipdeactivate
    REM This search/replace removes the previous env from the path
    ECHO Deactivating environment "%CONDA_DEFAULT_ENV%"...

    REM Run any deactivate scripts
    IF NOT EXIST "%CONDA_DEFAULT_ENV%\etc\conda\deactivate.d" GOTO nodeactivate
        PUSHD "%CONDA_DEFAULT_ENV%\etc\conda\deactivate.d"
        FOR %%g IN (*.bat) DO CALL "%%g"
        POPD
    :nodeactivate

    REM Remove env name from PROMPT
    FOR /F "tokens=* delims=\" %%i IN ("%CONDA_DEFAULT_ENV%") DO SET "CONDA_OLD_ENV_NAME=%%~ni"
    call set PROMPT=%%PROMPT:[%CONDA_OLD_ENV_NAME%] =%%

    SET "CONDACTIVATE_PATH=%CONDA_DEFAULT_ENV%;%CONDA_DEFAULT_ENV%\Scripts;%CONDA_DEFAULT_ENV%\Library\bin"
    CALL SET "PATH=%%PATH:%CONDACTIVATE_PATH%=%%"
    SET CONDA_DEFAULT_ENV=
:skipdeactivate

CALL :NORMALIZEPATH CONDA_DEFAULT_ENV "%CONDA_NEW_PATH%"

ECHO Activating environment "%CONDA_DEFAULT_ENV%"...
SET "PATH=%CONDA_DEFAULT_ENV%;%CONDA_DEFAULT_ENV%\Scripts;%CONDA_DEFAULT_ENV%\Library\bin;%PATH%"
IF "%CONDA_NEW_NAME%"=="" (
   REM Clear CONDA_DEFAULT_ENV so that this is truly a "root" environment, not an environment pointed at root
   SET CONDA_DEFAULT_ENV=
   ) ELSE (
   SET "PROMPT=[%CONDA_NEW_NAME%] %PROMPT%"
)

REM Make sure that root's Scripts dir is on PATH, for sake of keeping activate/deactivate available.
CALL SET "PATH_NO_SCRIPTS=%%PATH:%SCRIPT_PATH%=%%"
IF "%PATH_NO_SCRIPTS%"=="%PATH%" SET "PATH=%PATH%;%SCRIPT_PATH%"

REM Run any activate scripts
IF NOT EXIST "%CONDA_DEFAULT_ENV%\etc\conda\activate.d" GOTO noactivate
    PUSHD "%CONDA_DEFAULT_ENV%\etc\conda\activate.d"
    FOR %%g IN (*.bat) DO CALL "%%g"
    POPD
:noactivate

REM Trim trailing semicolon, if any
IF "%PATH:~-1%"==";" SET "PATH=%PATH:~0,-1%"

REM Clean up any double colons we may have ended up with
SET "PATH=%PATH:;;=;%"

ENDLOCAL & (
    SET "PATH=%PATH%"
    SET "PROMPT=%PROMPT%"
    SET "CONDA_DEFAULT_ENV=%CONDA_DEFAULT_ENV%"
    SET "CONDA_PATH_BACKUP=%CONDA_PATH_BACKUP%"
)

EXIT /B

:NORMALIZEPATH
    SET "%1=%~dpfn2"
    EXIT /B

如有任何提示,我们将不胜感激。

我发现如果您在以下 CALL SET 中不再使用单引号:

REM Make sure that root's Scripts dir is on PATH, for sake of keeping activate/deactivate available.
CALL SET "PATH_NO_SCRIPTS=%%PATH:%SCRIPT_PATH%=%%"
IF "%PATH_NO_SCRIPTS%"=="%PATH%" SET "PATH=%PATH%;%SCRIPT_PATH%"

至:

REM Make sure that root's Scripts dir is on PATH, for sake of keeping 
activate/deactivate available.
CALL SET ""PATH_NO_SCRIPTS=%%PATH:%SCRIPT_PATH%=%%""
IF "%PATH_NO_SCRIPTS%"=="%PATH%" SET "PATH=%PATH%;%SCRIPT_PATH%"

帮我解决了这个问题。这是基于这个 answer

什么对我有用但出现了同样的错误。

创建另一个系统变量 P1变量值 是您安装 Anaconda 的位置(我的在此处):

C:\Program Files (x86)\Anaconda3\

在你的PATH变量中,把这两个放在前面:

%P1%\envs;%P1%\Scripts\;everything_else_here 

重新启动命令提示符并尝试再次激活 env。

我遇到了同样的问题,激活使用 conda 创建的环境也会出现这种情况。 由于杂乱无章的 Windows PATH 问题困扰了我很长时间,因此我的解决方案是创建一个 python 小工具来整理 PATH 变量。它可以通过

>pip install pywinpath

接着是

>pywinpath

或者您可以从单个文件中复制并粘贴源代码https://github.com/czamb/pywinpath/blob/master/pywinpath.py

或从https://github.com/czamb/pywinpath/releases

下载捆绑的.exe

然后在您的 PATH 符合 Windows 长度限制后,您可以在您的用户或系统 PATH 的开头添加 Anaconda 的条目。 调用Anaconda Promt,输入echo %PATH%,可以找到相关的条目,它们是前三个条目。

还有其他工具可以编辑 Windows PATH 变量:https://superuser.com/questions/297947/is-there-a-convenient-way-to-edit-path-in-windows-7