pdm-project / pdm-venv

A plugin for pdm that enables virtualenv management
https://pdm-project.github.io/pdm-venv
MIT License
24 stars 4 forks source link

Add `install` command #41

Closed leetschau closed 2 years ago

leetschau commented 2 years ago

Is your feature request related to a problem? Please describe. Install dependencies in virtual env is not straightforward.

Describe the solution you'd like Add a install command: pdm venv install [<env-name>].

Describe alternatives you've considered Or maybe pdm already has this tool?

Additional context Under the hood, this command do:

pdm export -f requirements > requirements.txt
eval $(pdm venv activate <env-name>)    # or the first virtualenv if <env-name> not provided in `install` command above
pip install -r requirements.txt
rm requirements.txt
frostming commented 2 years ago

It looks not useful to install to a specific venv without using it.

You just switch to that venv by pdm use and do pdm install

leetschau commented 2 years ago

@frostming I tried to install dependencies in the virtualenv with the following commands:

pdm venv create --name testenv --with venv 3.9
eval $(pdm venv activate testenv)
pdm install

However, it install dependencies into /pypackages folder, instead of ~/.local/share/pdm/venvs/myproject-xxx-testenv. So I think pdm install can not install dependencies in virtualenv. Are my operations above to install deps in virtualenv right?

Thanks.

frostming commented 2 years ago

By pdm use you tell PDM to use which interpreter and env, while pdm venv activate is only the shell magic same as the old . venv/bin/activate, it doesn't change the interpreter setting of PDM. The setting saved in .pdm.toml always takes precedence unless you have PDM_IGNORE_SAVED_PYTHON=1. You can verify the current interpreter with pdm info.

leetschau commented 2 years ago

So to build a virtualenv according to PDM project definitions, run:

pdm venv create ...
pdm use  # choose the interpreter in the virtualenv created above
pdm install

The install command suggested above is unnecessary. Thanks.

robogast commented 2 years ago

Hi, I also don't understand what's going on here:

what is going on? I would like to test different versions of libraries under the same python version, which I thought I could do using venv.

I see now that I shouldn't give a name using --name, given https://github.com/pdm-project/pdm-venv/issues/32, but I don't think that's obvious. Even then, I would expect packages to be placed under /home/<user>/.local/share/pdm/venvs/<env-name>/, not $PROJECT_ROOT/__pypackages__/