psychopy.tools.pkgtools
¶
Tools for working with packages within the Python environment.
Get the path to the user's PsychoPy package directory. |
|
Get a list of active distributions in the current environment. |
|
|
Add a distribution to the current environment. |
|
Install a package using the default package management system. |
|
Uninstall a package from the current distribution. |
Get a list of installed packages and their versions. |
|
|
Get the metadata for a specified package. |
|
Details¶
- psychopy.tools.pkgtools.getUserPackagesPath()[source]¶
Get the path to the user’s PsychoPy package directory.
This is the directory that plugin and extension packages are installed to which is added to sys.path when psychopy is imported.
- Returns:
Path to user’s package directory.
- Return type:
- psychopy.tools.pkgtools.getDistributions()[source]¶
Get a list of active distributions in the current environment.
- Returns:
List of paths where active distributions are located. These paths refer to locations where packages containing importable modules and plugins can be found.
- Return type:
- psychopy.tools.pkgtools.addDistribution(distPath)[source]¶
Add a distribution to the current environment.
This function can be used to add a distribution to the present environment which contains Python packages that have importable modules or plugins.
- Parameters:
distPath (str) – Path to distribution. May be either a path for a directory or archive file (e.g. ZIP).
- psychopy.tools.pkgtools.installPackage(package, target=None, upgrade=False, forceReinstall=False, noDeps=False, awaited=True, outputCallback=None, terminateCallback=None, extra=None)[source]¶
Install a package using the default package management system.
This is intended to be used only by PsychoPy itself for installing plugins and packages through the builtin package manager.
- Parameters:
package (str) – Package name (e.g., ‘psychopy-connect’, ‘scipy’, etc.) with version if needed. You may also specify URLs to Git repositories and such.
target (str or None) – Location to install packages to directly to. If None, the user’s package directory is set at the prefix and the package is installed there. If a target is specified, the package top-level directory must be added to sys.path manually.
upgrade (bool) – Upgrade the specified package to the newest available version.
forceReinstall (bool) – If True, the package and all it’s dependencies will be reinstalled if they are present in the current distribution.
noDeps (bool) – Don’t install dependencies if True.
awaited (bool) – If False, then use an asynchronous install process - this function will return right away and the plugin install will happen in a different thread.
outputCallback (function) – Function to be called when any output text is received from the process performing the install. Not used if awaited=True.
terminateCallback (function) – Function to be called when installation is finished. Not used if awaited=True.
extra (dict) – Extra information to be supplied to the install thread when installing asynchronously. Not used if awaited=True.
- Returns:
- If awaited=True:
True if the package installed without errors. If False, check ‘stderr’ for more information. The package may still have installed correctly, but it doesn’t work. Second value contains standard output and error from the subprocess.
- If awaited=False:
Returns the job (thread) which is running the install.
- Return type:
tuple or psychopy.app.jobs.Job
- psychopy.tools.pkgtools.uninstallPackage(package)[source]¶
Uninstall a package from the current distribution.
- Parameters:
package (str) – Package name (e.g., ‘psychopy-connect’, ‘scipy’, etc.) with version if needed. You may also specify URLs to Git repositories and such.
- Returns:
True if the package removed without errors. If False, check ‘stderr’ for more information. The package may still have uninstalled correctly, but some other issues may have arose during the process.
- Return type:
Notes
The –yes flag is appended to the pip command. No confirmation will be requested if the package already exists.
- psychopy.tools.pkgtools.getInstalledPackages()[source]¶
Get a list of installed packages and their versions.
- Returns:
List of installed packages and their versions i.e. (‘PsychoPy’, ‘2021.3.1’).
- Return type:
- psychopy.tools.pkgtools.getPackageMetadata(packageName)[source]¶
Get the metadata for a specified package.
- psychopy.tools.pkgtools.getPypiInfo(packageName, silence=False)[source]¶