It is impossible to guarantee that this is possible if you do not have enough system privileges that you can change the global path. Actually, on most computers that you donβt have, they donβt actually, and I think this is the main goal. In cases where you have enough privileges (worth a try, some systems still allow this for ordinary users, but many others do not), you can use:
setx PATH "%path%;yourpath"
edit and ps:
You can identify the drive letter without input if you know the drive label, something like this:
@echo off set label=DRIVENAME set cmd=WMIC logicaldisk WHERE volumename^^="%label%" GET caption FOR /F "tokens=1" %%G IN ('%cmd% ^| find ":"')DO set pydrive=%%G echo %pydrive%\pathtopython rem do your stuff here
the idle running inside the package inherits the path, but other instances will not. Itβs hard to verify completely tough.
An explanation of the script package above. The wmic command is not suitable for the windows command line command. One of them can use WMI to make WQL (SQL for WMI), as if the windows were a database. Databases contain many tables, in which case the computer is instructed to obtain a table called logicaldisk . The logicaldisk table has 38 columns and one row for each disk connected to the system. This is the way to a lot of data for this purpose. Thus, the data is filtered. WHERE forces the database to only spit out rows that contain a specific value, in which case it is only interested in rows in which the volumename columns are equal to DRIVENAME, you can also use the size of the serial number or any other criteria. Finally, GET is used to limit the columns that you return as results, since you are only interested in the name of the drive letter that you are asking. This is called the heading in the table, so you ask.
Since the command is a little long, so I put the command inside the variable (and not the result), this shortens the for line to fit the stack overflow. Since = needs to be escaped, I need to use the escape sequence ^ once again so that it is still capable in the for loop.
The for loop is used to capture the return value of the wmic command. Since the answer has many lines, I only filter lines containing the colon character. And put it in the pydrive variable.