1

I have a .bat I use to set some environment vars before running a few programs.

I'd like to permanently set these environment vars, but I don't want to do it manually if possible. Is there a shortcut here? Is there any flag I can set to permanently add to PATH ?

The code is from setupvars.bat made available with OpenVino :

set ROOT=%~dp0
call :GetFullPath "%ROOT%\.." ROOT
set SCRIPT_NAME=%~nx0

set "INTEL_OPENVINO_DIR=%ROOT%"
set "INTEL_CVSDK_DIR=%INTEL_OPENVINO_DIR%"

where /q libmmd.dll || echo Warning: libmmd.dll couldn't be found in %%PATH%%. Please check if the redistributable package for Intel(R) C++ Compiler is installed and the library path is added to the PATH environment variable. System reboot can be required to update the system environment.

:: OpenCV
if exist "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat" (
call "%INTEL_OPENVINO_DIR%\opencv\setupvars.bat"
) else (
set "OpenCV_DIR=%INTEL_OPENVINO_DIR%\opencv\x64\vc14\lib"
set "PATH=%INTEL_OPENVINO_DIR%\opencv\x64\vc14\bin;%PATH%"
)

:: OpenVX
set "OPENVX_FOLDER=%INTEL_OPENVINO_DIR%\openvx"
set "PATH=%INTEL_OPENVINO_DIR%\openvx\bin;%PATH%"

:: Inference Engine
set "InferenceEngine_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\share"
set "HDDL_INSTALL_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\hddl"
set "PATH=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Release;%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Debug;%HDDL_INSTALL_DIR%\bin;%PATH%"
if exist "%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\arch_descriptions" (
set "ARCH_ROOT_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\arch_descriptions"
)
:: Check if Python is installed
python --version 2>NUL
if errorlevel 1 (
   echo Error^: Python is not installed. Please install Python 3.5. or 3.6  ^(64-bit^) from https://www.python.org/downloads/
   exit /B 1
)

:: Check Python version
for /F "tokens=* USEBACKQ" %%F IN (`python --version 2^>^&1`) DO (
   set version=%%F
)
echo %var%

for /F "tokens=1,2,3 delims=. " %%a in ("%version%") do (
   set Major=%%b
   set Minor=%%c
)

if "%Major%" geq "3" (
   if "%Minor%" geq "5" (
      set python_ver=okay
   )
   if "%Minor%" geq "6" (
     set python_ver=okay
   )
)

if not "%python_ver%"=="okay" (
   echo Unsupported Python version. Please install Python 3.5 or 3.6  ^(64-bit^) from https://www.python.org/downloads/
   exit /B 1
)

:: Check Python bitness
python -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2 > NUL
if errorlevel 1 (
   echo Error^: Error during installed Python bitness detection
   exit /B 1
)

for /F "tokens=* USEBACKQ" %%F IN (`python -c "import sys; print(64 if sys.maxsize > 2**32 else 32)" 2^>^&1`) DO (
   set bitness=%%F
)

if not "%bitness%"=="64" (
   echo Unsupported Python bitness. Please install Python 3.5 or 3.6  ^(64-bit^) from https://www.python.org/downloads/
   exit /B 1
)

set PYTHONPATH=%INTEL_OPENVINO_DIR%\python\python%Major%.%Minor%;%PYTHONPATH%

echo PYTHONPATH=%PYTHONPATH%

echo [setupvars.bat] OpenVINO environment initialized

exit /B 0

:GetFullPath
SET %2=%~f1

GOTO :EOF
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180
  • 1
    see help `setx /?` – elzooilogico Jun 21 '19 at 11:29
  • 1
    But don't use `setx` to modify __system__ or __user__ `PATH` respectively use it very wisely or otherwise you are corrupting __system__ or __user__ `PATH`. I recommend reading [Why are other folder paths also added to system PATH with SetX and not only the specified folder path?](https://stackoverflow.com/a/25919222/3074564) and [How to search and replace a string in environment variable PATH?](https://stackoverflow.com/a/24650324/3074564) and [Adding the current directory to Windows path permanently](https://stackoverflow.com/a/47080452/3074564). – Mofi Jun 21 '19 at 12:42
  • 1
    For better understanding what I mean take a look on [this question](https://stackoverflow.com/q/56684406/3074564) from yesterday where a user executed most likely a bad coded batch file with something like `setx PATH "C:\Whatever Folder Path;%PATH%" /M` with the result of all environment variable references replaced now by expanded strings, duplicate folder paths in __user__ and __system__ `PATH` and truncated `PATH`s because `setx` is limited to 1024 characters which is not much on many folder paths (useless or not really needed) in __system__ `PATH`. – Mofi Jun 21 '19 at 13:44

1 Answers1

1

For OpenVINO, you need to run the setupvars.sh script every time you open a command line. However, you can also add all the variables needed to your systems environment variables.

On your Windows® 10 system, go to Control Panel > System and Security > System > Advanced System Settings > Environment Variables.

See this document for a list of required variables and their values.

jgespino
  • 34
  • 3