Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing modules on portable python

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.

like image 338
PPTim Avatar asked Apr 30 '10 17:04

PPTim


People also ask

How do I import an external module?

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.

How do I install an external module in Python?

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.

Can you manually import a module in Python?

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.


2 Answers

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).

like image 190
Alex Martelli Avatar answered Oct 19 '22 09:10

Alex Martelli


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.

like image 21
Stéphane Laurent Avatar answered Oct 19 '22 08:10

Stéphane Laurent