I am running PortablePython_1.1_py2.6.1 on a USB stick. My code relies on some modules that are not preinstalled. Does anyone know whether it is possible to add new modules to a portable python installation? Simply copying in folders into site-lib does not seem to work.
Download and install External Modules in Python We just need to use the word import followed by the module name. As shown below. This will give us access to all the functions, classes and statements if any that are within the Math module.
In order to use an external module, you must first install it on your machine. To install, you'll need to download the files from the internet to your computer, then integrate them with the main Python library so that the language knows where the module is located.
append() Function. This is the easiest way to import a Python module by adding the module path to the path variable. The path variable contains the directories Python interpreter looks in for finding modules that were imported in the source files.
What does import sys; print sys.path
say? It should be the list of directories and zipfiles where Python (portable or otherwise) looks for modules to import. Just copy your modules into one of those directories or zipfiles, or sys.path.append('/whatever/dir')
if you have your modules in /whatever/dir
and want to keep them there (the latter approach will last only for the current session, be it interactive or a script's execution).
This closed question was actually asked for Portable Python 3.2. I have found a nice way to install modules with Windows :
download the zip archive of the distribute module
install it by typing
MyPythonPath\App\python MyDownloadPath\setup.py install
in a DOS commander
Now Easy Install is installed in folder MyPythonPath\App\Scripts. So type e.g.
MyPythonPath\App\Scripts\easy_install-3.2 numpy
to install the numpy module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With