Anaconda prompt loading error: The input line is too long
Asked Answered
G

3

5

I installed Anaconda 64 python 2.7 on Windows 7 64-bit version. After installation, the anaconda prompt can start with no problem. But whenever I restart/shutdown and restart the laptop, the anaconda prompt will display the following error message, and some python packages have problems to load in the 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\12.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 Server\110
\Tools\Binn\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files (x86
)\Windows Kits\8.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.

I tried to follow the solutions here and here, but with no success.

I looked into the Script folder under Anaconda, and found the error message might come from the activate.bat file. But I have no clue what to do next.

@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

Any hint is appreciated.

Grapery answered 15/1, 2016 at 19:21 Comment(1)
I would assume it is bombing on this line of code because once the variables expand it is longer then the maximum line length for a command. CALL SET "PATH_NO_SCRIPTS=%%PATH:%SCRIPT_PATH%=%%"Haemato
S
14

I found that if you change from using single quotes for the CALL SET on the following:

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%"

to:

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%"

Solves this issue for me. This is based upon this answer

Spread answered 1/2, 2016 at 18:50 Comment(4)
Thanks. Based on your answer, I changed the IF NOT "%PATH_NO_ROOT%"=="%PATH%" SET "CONDA_DEFAULT_ENV=%ROOT_PATH%" in line 51 to IF NOT "%PATH_NO_ROOT%"=="%PATH%" SET ""CONDA_DEFAULT_ENV=%ROOT_PATH%"", and it works for me.Grapery
I am struggling this problem and have changed all places of "CALL SET" like you guided. But it does not work for me even though anaconda can activate the variables. What I am saying here is not to use the commands like ls, rm,... (Linux-based commands).Behlau
While this may resolve the error message, it does not work. The comment says "Make sure that root's Scripts dir is on PATH, for sake of keeping activate/deactivate available.", but this does not happen. With this "fix", I can not deactivate my virtual env, nor activate another one.Jennajenne
@EmilStyrke I believe you are right. The problem is that some of the script directories are removed from the path. This should probably be reported upstream.Spread
D
3

What worked for me with the same error.

Create another system variable P1 with the variable value being the location of where your Anaconda install is (mine is here):

C:\Program Files (x86)\Anaconda3\

In your PATH variable, put these two at the front:

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

Restart command prompt and try to activate env again.

Dunghill answered 16/2, 2016 at 17:48 Comment(1)
Why would having a PATH variable be any better than just typing in the path (as is the default)?Unctuous
X
2

I had the same problem, it also occurs with activating environments created with conda. Because I was annoyed for a long time by problems from a messy Windows PATH, my solution was to create a little python tool to declutter the PATH variable. It is available via a

>pip install pywinpath

followed by

>pywinpath

Or you can copy & paste the source code from the single file https://github.com/czamb/pywinpath/blob/master/pywinpath.py

Or download the bundled .exe from https://github.com/czamb/pywinpath/releases

Then after you PATH fits inside the Windows length restrictions, you can add Anaconda's entries at the beginning of your user or system PATH. The relevant entries can be found by calling the Anaconda Promt and entering echo %PATH%, they are the first three entries.

There are also other tools to edit the Windows PATH variable: https://superuser.com/questions/297947/is-there-a-convenient-way-to-edit-path-in-windows-7

Xuanxunit answered 4/5, 2016 at 13:24 Comment(1)
by pywinpath: %envvar% goes to -> c:\user\robgrzel\%envvar% and that is not nice!Stationery

© 2022 - 2024 — McMap. All rights reserved.