Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Install a Python package
| ResourceFunction["PythonPackageInstall"]["name"] installs the Python package "name". | |
| ResourceFunction["PythonPackageInstall"][{"name1","name2",…}] installs packages "namei". | |
| ResourceFunction["PythonPackageInstall"][packages] installs the specified versions of the packages. | |
| ResourceFunction["PythonPackageInstall"][python,packages] installs for the given Python installation. | 
| "InstalledDependencies" | an association of installed package dependencies | 
Install a Python package:
| In[1]:= | ![ResourceFunction["PythonPackageInstall"]["tornado"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/7c48b5f860e5f506.png) | 
| Out[1]= |  | 
Uninstall it:
| In[2]:= | ![ResourceFunction["PythonPackageUninstall"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/1008d7dfe266d5c4.png) | 
| Out[2]= |  | 
Install a package with dependencies:
| In[3]:= | ![ResourceFunction["PythonPackageInstall"]["tst"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/200e350d6ea3211d.png) | 
| Out[3]= |  | 
List the installed dependencies:
| In[4]:= | ![%["InstalledDependencies"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/30185f3362fae2b7.png) | 
| Out[4]= |  | 
Uninstall the package with its dependencies:
| In[5]:= | ![ResourceFunction["PythonPackageUninstall"][%%]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/5d9a03728d110fa9.png) | 
| Out[5]= |  | 
Install several packages:
| In[6]:= | ![ResourceFunction["PythonPackageInstall"][{"tst", "tornado"}]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/6bc1c2563594c7f0.png) | 
| Out[6]= |  | 
Uninstall the packages:
| In[7]:= | ![ResourceFunction["PythonPackageUninstall"] /@ %](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/64f23e57176326c1.png) | 
| Out[7]= |  | 
Specify the required version using the Python convention:
| In[8]:= | ![ResourceFunction["PythonPackageInstall"]["camelcase==0.2"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/0ab039d945600bcd.png) | 
| Out[8]= |  | 
Clean up:
| In[9]:= | ![ResourceFunction["PythonPackageUninstall"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/1c3b562c56aeec8d.png) | 
| Out[9]= |  | 
Specify the version as a rule:
| In[10]:= | ![ResourceFunction["PythonPackageInstall"]["camelcase" -> "0.2"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/7c3e0a2169b0c084.png) | 
| Out[10]= |  | 
| In[11]:= | ![ResourceFunction["PythonPackageUninstall"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/4f23148ccf5763cf.png) | 
| Out[11]= |  | 
Or as an association:
| In[12]:= | ![ResourceFunction["PythonPackageInstall"][<|"camelcase" -> "0.2"|>]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/59622dccf1802d78.png) | 
| Out[12]= |  | 
| In[13]:= | ![ResourceFunction["PythonPackageUninstall"][%]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/646427431b87b744.png) | 
| Out[13]= |  | 
Make use of the same external session:
| In[14]:= | ![session = StartExternalSession["Python"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/748cd13efff5c8a9.png) | 
| Out[14]= |  | 
| In[15]:= | ![ResourceFunction["PythonPackageInstall"][session, "camelcase"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/749adfc721b231da.png) | 
| Out[15]= |  | 
| In[16]:= | ![ResourceFunction["PythonPackageUninstall"][session, %]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/374aab21ac07f690.png) | 
| Out[16]= |  | 
End the session:
| In[17]:= | ![DeleteObject[session]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/05afce4a2b1b7fe9.png) | 
In case of an error, the Failure object may contain a useful information returned by the underlying pip install command:
| In[18]:= | ![ResourceFunction["PythonPackageInstall"]["foo"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/3ea4e63a55c664c2.png) | 
| Out[19]= |  | 
PythonPackageInstall returns a Success object if the required version is already installed, or not specified:
| In[20]:= | ![session = StartExternalSession["Python"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/09c55ebb1367d070.png) | 
| Out[20]= |  | 
| In[21]:= | ![ResourceFunction["PythonPackageInstall"][session, "camelcase"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/3b5ff74fde4c867f.png) | 
| Out[21]= |  | 
| In[22]:= | ![success = ResourceFunction["PythonPackageInstall"][session, "camelcase"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/1d66ca36dca5ac3a.png) | 
| Out[22]= |  | 
| In[23]:= | ![ResourceFunction["PythonPackageInstall"][session, "camelcase==0.2"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/65bdfcc05503021d.png) | 
| Out[23]= |  | 
If the versions do not match, PythonPackageInstall returns a Failure object:
| In[24]:= | ![failure = ResourceFunction["PythonPackageInstall"][session, "camelcase==0.3"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/1a1c655adcbb1688.png) | 
| Out[24]= |  | 
Both Success and Failure objects with the tag "PythonPackageAlreadyInstalled" contain the location of the installed package:
| In[25]:= | ![#["Location"] & /@ {success, failure}](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/16f77e372e02bc97.png) | 
| Out[25]= |  | 
| In[26]:= | ![ResourceFunction["PythonPackageUninstall"][session, "camelcase"]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/3a739cf818d42885.png) | 
| Out[26]= |  | 
| In[27]:= | ![DeleteObject[session]](https://www.wolframcloud.com/obj/resourcesystem/images/dbe/dbe64413-4314-4730-870b-0a1aad930b7b/74603db7e346a4d6.png) | 
This work is licensed under a Creative Commons Attribution 4.0 International License