Function Repository Resource:

DeletePythonVirtualEnvironment

Source Notebook

Delete a Python virtual environment

Contributed by: Wolfram Staff

ResourceFunction["DeletePythonVirtualEnvironment"]["uuid"]

deletes the Python virtual environment with the specified registration UUID.

ResourceFunction["DeletePythonVirtualEnvironment"]["executable"]

deletes the virtual environment corresponding to the executable Python file.

ResourceFunction["DeletePythonVirtualEnvironment"]["dir"]

deletes the virtual environment in the directory "dir".

Details

ResourceFunction["DeletePythonVirtualEnvironment"] unregisters the specified Python system and deletes its directory, returning the UUID of the deleted Python system or a Failure object.
ResourceFunction["DeletePythonVirtualEnvironment"] deletes a virtual environment created with the repository CreatePythonVirtualEnvironment or an environment created on the command line and registered in the Wolfram System.
The convention for specifying the directory name "dir" is the same as in CreateDirectory; File["dir"] is also supported.
"executable" can be a relative or absolute file name or File["executable"].

Examples

Basic Examples (3) 

Create a Python virtual environment and delete it using its UUID:

In[1]:=
ResourceFunction["CreatePythonVirtualEnvironment"][<|
  "System" -> "Python", "Version" -> "3.9.5"|>, "virtual"]
Out[1]=
In[2]:=
ResourceFunction["DeletePythonVirtualEnvironment"][%]
Out[2]=

Delete it using the directory name:

In[3]:=
dir = "virtual";
In[4]:=
ResourceFunction["CreatePythonVirtualEnvironment"][<|
  "System" -> "Python", "Version" -> "3.9.5"|>, dir]
Out[4]=
In[5]:=
ResourceFunction["DeletePythonVirtualEnvironment"][dir]
Out[5]=

Delete it using the executable file location:

In[6]:=
ResourceFunction["CreatePythonVirtualEnvironment"][<|
  "System" -> "Python", "Version" -> "3.9.5"|>, "virtual"]
Out[6]=
In[7]:=
FindExternalEvaluators["Python"][%]["Executable"]
Out[7]=
In[8]:=
ResourceFunction["DeletePythonVirtualEnvironment"][%]
Out[8]=

Properties and Relations (3) 

The resource function CreatePythonVirtualEnvironment automatically creates intermediate directories:

In[9]:=
dir = FileNameJoin[{"MyExperiments", "1", "2", "MyEnvironment"}]
Out[9]=
In[10]:=
id = ResourceFunction["CreatePythonVirtualEnvironment"][<|
   "System" -> "Python", "Version" -> "3.9.5"|>, dir]
Out[10]=

DeletePythonVirtualEnvironment, on the other hand, deletes only the directory that contains the environment, leaving the intermediate directories in place:

In[11]:=
ResourceFunction["DeletePythonVirtualEnvironment"][id]
Out[11]=
In[12]:=
FileNames["*", FileNameJoin[{"MyExperiments", "1", "2"}]]
Out[12]=

Delete the directories to clean up:

In[13]:=
DeleteDirectory["MyExperiments", DeleteContents -> True]

Version History

  • 1.0.1 – 08 February 2022
  • 1.0.0 – 18 May 2021

Related Resources

License Information