Wolfram Research

Function Repository Resource:

PythonPackageInstall

Source Notebook

Install a Python package

Contributed by: Wolfram Staff

ResourceFunction["PythonPackageInstall"]["name"]

installs the Python package "name".

ResourceFunction["PythonPackageInstall"][{"name1","name2",}]

installs packages "namei".

ResourceFunction["PythonPackageInstall"][python,package]

installs for the given Python installation.

Details and Options

ResourceFunction["PythonPackageInstall"][name] attempts to install the specified package and returns a Success object if it was successfully installed and a Failure object otherwise.
If the specified package is already installed, ResourceFunction["PythonPackageInstall"] returns a Success object with the tag "PythonPackageAlreadyInstalled".
For successful installation, the Success object can contain the following key:
"InstalledDependencies" an association of installed package dependencies
"InstalledDependencies" does not necessarily list all the package dependencies but only the ones that have been installed during the current installation run.
ResourceFunction["PythonPackageInstall"][name] is effectively equivalent to executing the command line pip install name.
In ResourceFunction["PythonPackageInstall"][python,package], the value for python can be a path to a Python executable or an ExternalSessionObject.

Examples

Basic Examples

Install a Python package:

In[1]:=
ResourceFunction["PythonPackageInstall"]["tornado"]
Out[1]=

Uninstall it:

In[2]:=
ResourceFunction["PythonPackageUninstall"][%]
Out[2]=

Install a package with dependencies:

In[3]:=
ResourceFunction["PythonPackageInstall"]["tst"]
Out[3]=

List the installed dependencies:

In[4]:=
%["InstalledDependencies"]
Out[4]=

Uninstall the package with its dependencies:

In[5]:=
ResourceFunction["PythonPackageUninstall"][%%]
Out[5]=

Install several packages:

In[6]:=
ResourceFunction["PythonPackageInstall"][{"tst", "tornado"}]
Out[6]=

Uninstall the packages:

In[7]:=
ResourceFunction["PythonPackageUninstall"] /@ %
Out[7]=

Resource History

Source Metadata

Related Resources

License Information