Environment
Wine Python environments can be created, managed and destroyed using this API.
- class wenv.Env(**kwargs)
Represents one Wine Python environment. Mutable.
- Parameters
kwargs (
Any) – An arbitrary number of keyword arguments matching valid configuration options. In previous releases, the constructor expected one optional argument,parameter. It should either beNoneor a dictionary. In the latter case, the dictionary may contain all valid configuration options.parametercan still be used but is deprecated.
- cache()
Equivalent to
wenv cache. It fetches installation files and caches them for offline usage, including the Python interpreter, pip, setuptools and wheel.
- cache_package(name)
Caches a specific package by nameself.
- Parameters
name (
str) – Name of PyPI package
- cli()
Command line interface entry point. Equivalent to
wenv [...]. Looks for sub-commands and parameters insys.argv.
- cpython_31542_pth_workaround()
Deletes pth-file or reconstructs it from backup depending on
no_pth_fileconfiguration parameter. Relevant for prepending""tosys.pathin CPython >= 3.11 thanks to CPython PR #31542. This function works around “Modules/getpath.py sets safe_path to 1 if a “._pth” file is present”.
- ensure()
Equivalent to
wenv init. Intended to be used by 3rd-party packages which want to “ensure” thatwenvhas been initialized (i.e. Python and pip are present and working).ensure()calls the following methods:
- install_package(name, update=False)
Thin wrapper for
wenv pip install {-U} {name}. Installs and/or updates a package.- Parameters
name (
str) – Name of PyPI packageupdate (
bool) – Update flag
- list_packages()
Thin wrapper for
wenv pip list --format json.- Return type
List[Dict[str,str]]- Returns
A list of dictionaries of format
{"name": "Name of PyPI package ", "version": "package version"}.
- setup_coverage_activate()
Equivalent to
wenv init_coverage. It enables coverage analysis inside wenv.
- setup_pip()
Part of the initialization process, but can be triggered on its own if required. It installs
pip, assuming that both thewineprefixandpythonprefixare already present.
- setup_pythonprefix(overwrite=False)
Part of the initialization process, but can be triggered on its own if required. It installs the CPython interpreter into the Python prefix.
- Parameters
overwrite (
bool) – If set toTrue, a pre-existing Python prefix is removed before a new one is created.
- setup_wineprefix(overwrite=False)
Part of the initialization process, but can be triggered on its own if required. It creates a Wine prefix according to wenv’s configuration.
- Parameters
overwrite (
bool) – If set toTrue, a pre-existing Wine prefix is removed before a new one is created.
- shebang()
shebang entry point for Wine Python interpreter. Equivalent to
_wenv_python [...]. Does not look atsys.argv. It only passessys.argv[1]on to the Wine Python interpreter.This interface is working around a lack of Unix specification, see:
- uninstall()
Equivalent to
wenv clean. It removes the current Wine Python environment, i.e. Python interpreter, pip, setuptools, wheel and all installed packages.
- uninstall_package(name)
Thin wrapper for
wenv pip uninstall -y {name}. Removes a package.- Parameters
name (
str) – Name of PyPI package
- wine_47766_workaround()
Due to Wine bug #47766 (in
PathAllocCanonicalize), Wine crashes if any folder in the path topythonprefixis hidden Unix-style (i.e. prefixed with a dot /.). This workaround creates a symlink directly pointing topythonprefixinto/tmp, which is (more or less) guaranteed to be visible. It is then used instead of the actualpythonprefix.Run
setup_wineprefixandsetup_pythonprefixbefore callingwine_47766_workaround. Any subsequent action such as installing or usingpipmust happen after callingwine_47766_workaround.
- wine_47766_workaround_uninstall()
Reverts the Wine bug #47766 workaround, i.e. it removes the symlink.