(Deprecated)A plugin for pdm that enables virtualenv management
Project description
pdm-venv
A plugin for pdm that enables virtualenv management
DEPRECATION WARNING
venv support will be integrated into the pdm
after 2.0.0
. This project is not necessary and won't be maintained anymore.
The last version of PDM it supports is 1.15
.
Requirements
pdm-venv requires Python>=3.7
Installation
On PDM 1.6.4+, you can install the plugin directly by:
$ pdm plugin add pdm-venv
If pdm
is installed via pipx(the recommended way), run:
$ pipx inject pdm pdm-venv
Otherwise if pdm
is installed via Homebrew, run:
$ $(brew --prefix pdm)/libexec/bin/pip install pdm-venv
Or install with pip
to the user site:
$ python -m pip install --user pdm-venv
Note that pdm-venv
must be installed to the same environment as pdm
.
Usage
pdm-venv
enhances pdm
's CLI with the support of virtualenv creation and management. With pdm-venv
installed,
the default value of python.use_venv
will turn to True
, you can disable the whole plugin by pdm config python.use_venv false
.
Create a virtualenv
# Create a virtualenv based on 3.8 interpreter
$ pdm venv create 3.8
# Assign a different name other than the version string
$ pdm venv create --name for-test 3.8
# Use venv as the backend to create, support 3 backends: virtualenv(default), venv, conda
$ pdm venv create --with venv 3.9
List all virtualenv created with this project
$ pdm venv list
Virtualenvs 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.1
The name before the colon(:) is the key of the virtualenv which is used in remove
and activate
commands below.
Remove a virtualenv
$ pdm venv remove for-test
Virtualenvs created with this project:
Will remove: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test, continue? [y/N]:y
Removed C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test
Activate a virtualenv
Instead of spawning a subshell like what pipenv
and poetry
do, pdm-venv
doesn'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 to eval
to activate the virtualenv without leaving the current shell:
Bash/csh/zsh
$ eval $(pdm venv activate for-test)
(test-project-8Sgn_62n-for-test) $ # Virtualenv entered
Fish
$ eval (pdm venv activate for-test)
Powershell
PS1> 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 by pdm_venv_activate $venv_name
and deactivate by deactivate
directly.
Additionally, if the saved Python interpreter is a venv Python, you can omit the name argument following activate
.
Switch Python interpreter
When pdm-venv
is enabled, Python interpreters associated with the venvs will also show in the interpreter list of pdm use
or pdm init
command.
Additionally, if pdm
detects it is inside an active virtualenv by examining VIRTUAL_ENV
env var, it will reuse that virtualenv for later actions.
Virtualenv auto creation
If no Python interpreter is selected for the project, pdm-venv
will take charge to create one for you and select the venv interpreter automatically, just like
what pipenv
and poetry
do. Additionaly, if config item venv.in_project
is True
, pdm-venv
will create the virtualenv in ${PROJECT_ROOT}/.venv
.
Configuration
Config Item | Description | Default Value | Available in Project | Env var |
---|---|---|---|---|
venv.location |
The root directory to store virtualenvs | appdirs.user_data_dir() / "venvs" |
No | |
venv.backend |
The default backend used to create virtualenvs | virtualenv |
No | |
venv.in_project |
Create virtualenv in .venv under project root |
False |
Yes | PDM_VENV_IN_PROJECT |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pdm-venv-0.6.0.tar.gz
.
File metadata
- Download URL: pdm-venv-0.6.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 962a336d53a86b5302a7cb90eba836f1a2b08e8f0fe02ad28bf1b19ce5d9cf88 |
|
MD5 | 4928cfaf2f927dd948ff47fa212ee765 |
|
BLAKE2b-256 | e2a9583e088f5ddf22d1c1f4ceb566932b282a48f897ac8d561ce5410a5eeb65 |
File details
Details for the file pdm_venv-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: pdm_venv-0.6.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0034c689b142e61eb8f0fe64f05b91dcf4d9325ec5415c413170eb8829ed3cbd |
|
MD5 | a2094be414314069e83b43be8d5326ef |
|
BLAKE2b-256 | ecc032ac9120ff973cad04497b8ac0f1b45e721a21fafcb21286fb62fcbec949 |