J2897

Python Environment Checker

Feb 4th, 2021 (edited)
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.55 KB | None | 0 0
  1. @echo OFF
  2. title Python Environment Checker
  3.  
  4. :: Displays information about your current Python environment.
  5. ::
  6. :: Administrator privileges are normally required for GLOBAL uninstallations
  7. :: of modules:
  8. :: python -m pip uninstall <package>
  9. ::
  10. :: To uninstall all USER modules:
  11. :: python -m pip freeze --user > "%TEMP%\requirements.txt"
  12. :: python -m pip uninstall -r "%TEMP%\requirements.txt"
  13.  
  14. cls
  15. set "TAB=   "
  16.  
  17. REM Get the Python version.
  18. for /f "tokens=2" %%V in ('python --version') do (
  19.     set "PV=%%V"
  20. )
  21.  
  22. echo Basic information regarding your Python %PV% environment:
  23. echo.
  24. echo Install locations...
  25. echo.
  26.  
  27. REM Get the Python location.
  28. for /f "tokens=*" %%P in ('where python.exe') do (
  29.     set "PYTHON_LOCATION=%%P"
  30. )
  31. echo [PYTHON]%TAB%%PYTHON_LOCATION%
  32.  
  33. REM Get the Py location.
  34. for /f "tokens=*" %%P in ('where py.exe') do (
  35.     set "PY_LOCATION=%%P"
  36. )
  37. echo [PY]%TAB%%TAB%%PY_LOCATION%
  38.  
  39. REM Get the PIP location.
  40. for /f "tokens=*" %%P in ('where pip.exe') do (
  41.     set "PIP_LOCATION=%%P"
  42. )
  43. echo [PIP]%TAB%%TAB%%PIP_LOCATION%
  44. echo.
  45.  
  46. echo The modules...
  47. echo.
  48.  
  49. REM Show user "site-packages" location.
  50. echo [USER]
  51. python -m pip list --user
  52. for /f "tokens=*" %%P in ('python -m site --user-site') do (
  53.     set "USER_SITE_PACKAGES=%%P"
  54. )
  55. echo [%USER_SITE_PACKAGES%]
  56. echo.
  57.  
  58. REM Show global "site-packages" location.
  59. echo [GLOBAL]
  60. python -m pip list --local
  61. for /f "tokens=*" %%N in ('python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])"') do (
  62.     set "GLOBAL_SITE_PACKAGES=%%N"
  63. )
  64. echo [%GLOBAL_SITE_PACKAGES%]
  65. echo.
  66.  
  67. pause
Add Comment
Please, Sign In to add comment