3

I want to create a completely autonomous Python environment on an USB pen drive that can run both on Windows and GNU/Linux....

How can I do that ?

I've tried to build Python with `./' as prefix, but it doesn't works... anyone has another idea ?

Thanks in advance...

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 1
    For Windows, try http://www.portablepython.com/. I don't know of anything equivalent for Linux, but Linux systems usually have Python on already. – Thomas K Jan 30 '11 at 13:18
  • 2
    Running both on Windows and Linux is pretty much impossible, unless if you make two builds (of if you use WINE, perhaps). –  Jan 30 '11 at 13:41
  • PortablePython looks like a distribution of the official CPython for windows, but it seems not dependent of any absolute directory... I'll see the source code... –  Jan 30 '11 at 13:45

1 Answers1

4

Ok, i've looked at http://svn.python.org/projects/python/branches/release31-maint/ and i found an interesting «readme» talking about a «pyconfig.h» file.

In http://svn.python.org/projects/python/branches/release31-maint/PC/pyconfig.h at line 82-83, there is the solution of my problem:

#ifndef PYTHONPATH
#   define PYTHONPATH L".\\DLLs;.\\lib;.\\lib\\plat-win"

I think if i change the value of the «PYTHONPATH» define, i'll get a python interpreter seeking his files in a relative directory, so I'll just have to build it both for GNU/Linux and Window, and to put the both executables on a pen-drive, then i'll get a portable Python environment !

I'm trying this, and I'll keep you posted ...


EDIT: Finally, it works ! I've built Python like this:

make PYTHONPATH=../lib:../Lib:./lib:./Lib

... and now Python seeks the modules in `../lib' !

I will build it both for GNU/Linux and Windows, and i'll put it on an USB pen-drive, like this:

/mnt/key/
├── AUTORUN.INF 
├── Lib
│   ├── os.py
│   ├── sys.py
│   ├── ...
│   └── (Here i'll put the Python Standard Library)
├── Linux
│   └── python
└── Windows
    ├── python.exe
    └── pythonw.exe

Thanks all