Package: pdm-venv
pdm-venvA plugin for pdm that enables virtualenv managementDEPRECATION WARNINGvenv support will be integrated into thepdmafter2.0.0. This project is not necessary and won't be maintained anymore.
The last version of PDM it supports is1.15.Requirementspdm-venv requires Python>=3.7InstallationOn PDM 1.6.4+, you can install the plugin directly by:$pdmpluginaddpdm-venvIfpdmis installed viapipx(the recommended way), run:$pipxinjectpdmpdm-venvOtherwise ifpdmis installed via Homebrew, run:$$(brew--prefixpdm)/libexec/bin/pipinstallpdm-venvOr install withpipto the user site:$python-mpipinstall--userpdm-venvNote thatpdm-venvmust be installed to the same environment aspdm.Usagepdm-venvenhancespdm's CLI with the support of virtualenv creation and management. Withpdm-venvinstalled,
the default value ofpython.use_venvwill turn toTrue, you can disable the whole plugin bypdm config python.use_venv false.Create a virtualenv# Create a virtualenv based on 3.8 interpreter$pdmvenvcreate3.8# Assign a different name other than the version string$pdmvenvcreate--namefor-test3.8# Use venv as the backend to create, support 3 backends: virtualenv(default), venv, conda$pdmvenvcreate--withvenv3.9List all virtualenv created with this project$pdmvenvlistVirtualenvs created with this project:-  3.8.6: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-3.8.6-  for-test: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test-  3.9.1: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-3.9.1The name before the colon(:) is the key of the virtualenv which is used inremoveandactivatecommands below.Remove a virtualenv$pdmvenvremovefor-testVirtualenvs created with this project:Will remove: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test, continue? [y/N]:yRemoved C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-testActivate a virtualenvInstead of spawning a subshell like whatpipenvandpoetrydo,pdm-venvdoesn't create the shell for you but print the activate command to the console.
In this way you won't lose the fancy shell features. You can then feed the output toevalto activate the virtualenv without leaving the current shell:Bash/csh/zsh$eval$(pdmvenvactivatefor-test)(test-project-8Sgn_62n-for-test)$# Virtualenv enteredFish$eval(pdmvenvactivatefor-test)PowershellPS1> Invoke-Expression (pdm venv activate for-test)You can make your own shell shortcut function to avoid the input of long command. Here is an example of Bash:pdm_venv_activate(){eval$('pdm''venv''activate'"$1")}Then you can activate it bypdm_venv_activate $venv_nameand deactivate bydeactivatedirectly.Additionally, if the saved Python interpreter is a venv Python, you can omit the name argument followingactivate.Switch Python interpreterWhenpdm-venvis enabled, Python interpreters associated with the venvs will also show in the interpreter list ofpdm useorpdm initcommand.Additionally, ifpdmdetects it is inside an active virtualenv by examiningVIRTUAL_ENVenv var, it will reuse that virtualenv for later actions.Virtualenv auto creationIf no Python interpreter is selected for the project,pdm-venvwill take charge to create one for you and select the venv interpreter automatically, just like
whatpipenvandpoetrydo. Additionaly, if config itemvenv.in_projectisTrue,pdm-venvwill create the virtualenv in${PROJECT_ROOT}/.venv.ConfigurationConfig ItemDescriptionDefault ValueAvailable in ProjectEnv varvenv.locationThe root directory to store virtualenvsappdirs.user_data_dir() / "venvs"Novenv.backendThe default backend used to create virtualenvsvirtualenvNovenv.in_projectCreate virtualenv in.venvunder project rootFalseYesPDM_VENV_IN_PROJECT