from direct.showbase.VFSImporter import VFSImporter, VFSLoader, VFSSharedImporter, VFSSharedLoader, register, reloadSharedPackage, reloadSharedPackages

The VFS importer allows importing Python modules from Panda3D’s virtual file system, through Python’s standard import mechanism.

Calling the register() function to register the import hooks should be sufficient to enable this functionality.

Inheritance diagram

Inheritance diagram of direct.showbase.VFSImporter

class VFSImporter(path)[source]

Bases: object

This class serves as a Python importer to support loading Python .py and .pyc/.pyo files from Panda’s Virtual File System, which allows loading Python source files from mounted .mf files (among other places).

__init__(self, path)[source]
find_module(self, fullname, path=None)[source]
class VFSLoader(dir_path, vfile, filename, desc, packagePath=None)[source]

Bases: object

The second part of VFSImporter, this is created for a particular .py file or directory.

__init__(self, dir_path, vfile, filename, desc, packagePath=None)[source]
get_code(self, fullname)[source]
get_filename(self, fullname)[source]
get_source(self, fullname)[source]
getdata(self, path)[source]
is_package(self, fullname)[source]
load_module(self, fullname, loadingShared=False)[source]
class VFSSharedImporter[source]

Bases: object

This is a special importer that is added onto the meta_path list, so that it is called before sys.path is traversed. It uses special logic to load one of the “shared” packages, by searching the entire sys.path for all instances of this shared package, and merging them.

find_module(self, fullname, path=None, reload=False)[source]
getLoadedDirname(self, mod)[source]

Returns the directory name that the indicated conventionally-loaded module must have been loaded from.

class VFSSharedLoader(loaders, reload)[source]

Bases: object

The second part of VFSSharedImporter, this imports a list of packages and combines them.

__init__(self, loaders, reload)[source]
load_module(self, fullname)[source]

Register the VFSImporter on the path_hooks, if it has not already been registered, so that future Python import statements will vector through here (and therefore will take advantage of Panda’s virtual file system).


Reloads the specific module as a shared package, adding any new directories that might have appeared on the search path.


Walks through the sharedPackages list, and forces a reload of any modules on that list that have already been loaded. This allows new directories to be added to the search path.

sharedPackages = {}

The sharedPackages dictionary lists all of the “shared packages”, special Python packages that automatically span multiple directories via magic in the VFSImporter. You can make a package “shared” simply by adding its name into this dictionary (and then calling reloadSharedPackages() if it’s already been imported).

When a package name is in this dictionary at import time, all instances of the package are located along sys.path, and merged into a single Python module with a __path__ setting that represents the union. Thus, you can have a in your own application, and loading it won’t shadow the system direct.showbase.ShowBase which is in a different directory on disk.