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. Answer What does import sys; print sys.path say? It should be the list of directories
Tag: module
How to import a Python class that is in a directory above?
I want to inherit from a class in a file that lies in a directory above the current one. Is it possible to relatively import that file? Answer from ..subpkg2 import mod Per the Python docs: When inside a package hierarchy, use two dots, as the import statement doc says: When specifying what module to import you do not have
What is __init__.py for?
What is __init__.py for in a Python source directory? Answer It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”). Here’s the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is
How do I unload (reload) a Python module?
I have a long-running Python server and would like to be able to upgrade a service without restarting the server. What’s the best way do do this? Answer You can reload a module when it has already been imported by using importlib.reload(): In Python 2, reload was a builtin. In Python 3, it was moved to the imp module. In
How do I find the location of Python module sources?
How do I learn where the source file for a given Python module is installed? Is the method different on Windows than on Linux? I’m trying to look for the source of the datetime module in particular, but I’m interested in a more general answer as well. Answer For a pure python module you can find the source by looking