Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Created August 6, 2014 14:55
Show Gist options
  • Save uranusjr/c7aff766460fabc0e4ee to your computer and use it in GitHub Desktop.
Save uranusjr/c7aff766460fabc0e4ee to your computer and use it in GitHub Desktop.
Create a Command Prompt shortcut with %Path% setup for a particular Python distribution
@echo off
setlocal
set /p PYTHONEXE="Drag and drop python.exe here, and press ENTER: "
for %%d in (%PYTHONEXE%) do set PYTHONROOT=%%~dpd
:: Strip trailing backslash.
set PYTHONROOT=%PYTHONROOT:~0,-1%
set PYTHONBAT=%PYTHONROOT%\python341.bat
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo @echo off > %PYTHONBAT%
echo set PATH=%PYTHONROOT%;%PYTHONROOT%\Scripts;%%PATH%% >> %PYTHONBAT%
echo cd /D %HOMEPATH% >> %PYTHONBAT%
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "%HOMEPATH%\Desktop\Django Environment.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "%COMSPEC%" >> %SCRIPT%
echo oLink.Arguments = "/A /Q /K %PYTHONBAT%" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment