- class starlark_pyoxidizer.PythonInterpreterConfig¶
This type configures the default behavior of the embedded Python interpreter.
Embedded Python interpreters are configured and instantiated using a Rust
pyembed::OxidizedPythonInterpreterConfigdata structure. The
pyembedcrate defines a default instance of this data structure with parameters defined by the settings in this type.
If you are writing custom Rust code and constructing a custom
pyembed::OxidizedPythonInterpreterConfiginstance and don’t use the default instance, this config type is not relevant to you and can be omitted from your config file.
Some of the settings exposed by Python’s initialization APIs are extremely low level and brittle. Various combinations can cause the process to crash/exit ungracefully. Be very cautious when setting these low-level settings.
Instances are constructed by calling
Instance state is managed via attributes.
There are a ton of attributes and most attributes are not relevant to most applications. The bulk of the attributes exist to give full control over Python interpreter initialization.
The following attributes control features provided by the
pyembedRust crate, which manages the embedded Python interpreter in generated executables. These attributes provide features and level of control over embedded Python interpreters beyond what is possible with Python’s initialization C API.
The following attributes correspond to fields of the PyPreConfig C struct used to initialize the Python interpreter.
The following attributes correspond to fields of the PyConfig C struct used to initialize the Python interpreter.
snmallocallocators require the presence of additional Rust crates. A run-time error will occur if these allocators are configured but the binary was built without these crates. (This should not occur when using
pyoxidizerto build the binary.)
When a custom allocator is configured, the autogenerated Rust crate used to build the binary will configure the Rust global allocator (
#[global_allocator] attribute) to use the specified allocator.
rustallocator is not recommended because it introduces performance overhead. But it may help with debugging in some situations.
cmakebuild tool to compile code as part of their build process. If this tool is not available in the build environment, you will encounter a build error with a message similar to
failed to execute command: The system cannot find the file specified. (os error 2) is `cmake` not installed?.
The workaround is to install cmake or use a different allocator.
snmalloconly supports targeting to macOS 10.14 or newer. You will likely see build errors when building a binary targeting macOS 10.13 or older.
jemallocon non-Windows targets and
defaulton Windows. (The
jemalloc-syscrate doesn’t work on Windows MSVC targets.)
The filesystem importer is enabled automatically if
Default value is
See Terminfo Database for more about terminal databases.
See hash_seed Field.
PyConfig.use_hash_seedwill automatically be set if this attribute is defined.
Setting this to a non-empty value also has the side-effect of setting
filesystem_importer = True
See site_import Field.
sitemodule is typically not needed for standalone/isolated Python applications.
PythonInterpreterConfig Starlark type is backed by a Rust data
structure. And when attributes are retrieved, a copy of the underlying
Rust struct field is returned.
This means that if you attempt to mutate a Starlark value (as opposed to assigning an attribute), the mutation won’t be reflected on the underlying Rust data structure.
config = dist.make_python_interpreter_config() # assigns vec!["foo", "bar"]. config.module_search_paths = ["foo", "bar"] # Creates a copy of the underlying list and appends to that copy. # The stored value of `module_search_paths` is still `["foo", "bar"]`. config.module_search_paths.append("baz")
To append to a list, do something like the following:
value = config.module_search_paths value.append("baz") config.module_search_paths = value