1

I've got a couple versions of Portable Python installed on my usb thumb drive so I can tinker with it when I'm away from my main computer, or if I want to try something with a different version.

Right now its installed under 'F:\Portable Python 2.7.2.1\App\python.exe', which gets to be a handful to type over and over. Granted, command-line history and tab-completion can alleviate some of the tedium, but I was wondering if there is a correct way to set things up so that instead of having to type that entire fully-qualified name plus the script name, I could simply type 'python myscript.py' and have 'python' point to the above executable (or have 'python3' point to f:\Portable Python 3.2.1.1) - without permanently installing python on the computer.

I tried using a simple .bat file named 'python.bat' that when called executed the named file... that worked until I either a) wound up on a different machine that assigned a different drive letter to the usb stick, or b) I tried running a script that took multiple command-line arguments, which apparently didn't make it 'through' the bat file.

Just thinking out loud, in *nix-y terms, I'm guessing I need to some how set the environment variable for $PATH for the session, and then unset it when I'm done. Probably a great first useful python script, but obviously I need a little help as far as whether I'm even headed in the right direction, etc.

TIA,

Monte

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
memilanuk
  • 3,522
  • 6
  • 33
  • 39

1 Answers1

0

If you were on *nix you could do a relative symbolic link

I would try making your directory names much less verbose and definitely take white space out of them. How complicated are things are on your flash drive? Would this not make sense?

F:\python\2.7\python.exe

I doubt you would have regular and portable python on your flash drive, but if you wanted just a little more description: F:\ppython\2.7\python.exe

To more directly answer you question run the below from cmd line,batch script,or execute from python:

set path =  "%PATH%;C:\Some Ridiculous Name with CaPiTals and Spaces\"

I would fix your directory structure and have a batch script on flash drive to temporarily set the environmental variable.

Community
  • 1
  • 1
Joe McGrath
  • 1,481
  • 10
  • 26
  • Hmmm... I had been just sticking with the default directory names as created by the Portable Python installer, but it probably wouldn't hurt anything to shorten them up a bit. Any suggestions on how to handle the changing drive letters easily i.e. I plug the usb stick into machine 'A' it auto-mounts as 'E:\' but when I plug it into machine 'B' it auto-mounts as 'F:\'. That was the problem I ran into with hard-coding the drive letter into the 'set path' statement. – memilanuk Dec 13 '11 at 17:34
  • Found the answer I was looking for... using the parameter '%~d0' to set the path to the current drive i.e. 'SET PATH=%PATH%;%~d0\path-to-desired-directory'. – memilanuk Dec 14 '11 at 17:45