Igle Igle - 1 year ago 97
Python Question

"(" cant be processed syntactically at this point”

I got a install batch, that should create a python

venv
in a chosen folder, activate it and then install packages with pip.

Unfortunately it keeps throwing
"(" cant be processed syntactically at this point
after the
echo #### Installing Packages
. I'm not that firm with writing batch script and could not figure out what I got wrong here. Could someone please give me a hand here?

echo ##### Installation Python AppApp

setlocal

if "%~1"=="" (
echo No params given
set "folder_chosen=false"
) else (
set "folder=%1"
set "folder_chosen=true"
)

setlocal enabledelayedexpansion

if "%folder_chosen%"=="false" (
call :CHOOSE_FOLDER
)

echo You chose !folder!

echo ##### Creating virtual environment
python -m venv !folder!\AppApp

echo ##### Activating virtual environment
call !folder!\AppApp\Scripts\activate

echo ##### Installing packages


if not "%HTTP_PROXY%"=="" (
pip install -r requirements.txt --proxy=%HTTP_PROXY%
) else (
echo Proxy not set
set /p "use_proxy=No proxy for pip configured, do you want to use one? [y]/n"

if %use_proxy%=="y" (

set /p "proxy_user=Enter username for proxy! [%USERNAME%]"
if "%proxy_user%"=="" set "proxy_user=%USERNAME%"
set /p "proxy_host=Enter proxy host! [default.proxy.de]"
if "%proxy_host%"=="" set "proxy_host=default.proxy.de"
set /p "proxy_port=Enter proxy port! [8080]"
if "%proxy_port"=="" set "proxy_port=8080"

pip install -r requirements.txt --proxy %proxy_user%@%proxy_host%:%proxy_port%
) else (
pip install -r requirements.txt
)
)

IF %ERRORLEVEL% NEQ 0 GOTO PIPError

echo ##### Copying runnables
cp initPythonCommands.py !folder!\AppApp
cp startPythonCmd.bat !folder!\AppApp

echo ##### Succesfully installed Python AppApp

endlocal
pause

exit /b 0

:PIPError
ECHO ##### Could not fetch package from pip, you might want to check your proxy settings
@call deactivate
ECHO ##### Removing the created Venv
rm -r !folder!\AppApp
pause
exit /b 1

:CHOOSE_FOLDER
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'Please choose a folder.',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "folder=%%I"
exit /b

Answer Source

You need to use delayed expansion inside of code blocks, if you use a variable changed in that block.

...
) else (
    setlocal enabledelayedexpansion
    set /p use_proxy="No proxy for pip configured, do you want to use one? [y]/n"

    if "%use_proxy%"=="y" (
    ...
)
...

Change if "%use_proxy%"=="y" to if "!use_proxy!"=="y"

(Note: there is no if (...) else (...) else (...) in cmd. Change your logic)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download