conda can create both project-specific (in project folder) and global environment. poetry can only create project-specific environment in a global path. However you can move the virtualenv into the project folder by specifying the virtualenv folder.
conda environment is more self-contained.
Because for poetry and venv, the Python interpreter in virtualenv is only a link to
the global python
.
While the interpreter is a real binary in a conda environment.
Conda
conda config --set env_prompt '({name})'
conda create --prefix ./envs jupyterlab=0.35 matplotlib=3.1 numpy=1.16
conda activate ./envs
Ref:
Section "Specifying a location for an environment" of Managing environments
Poetry
Poetry 创建虚拟环境的目录位置由 virtualenvs.path
确定,
默认值为 {cache-dir}/virtualenvs
,而 cache-dir
的默认值为 ~/.cache/pypoetry/virtualenvs
,
这样的一个问题是废弃的 poetry 项目的虚拟环境仍然在磁盘上占空间,
更好的方法是采用 venv
的方式:把虚拟环境放在项目文件夹下,
实现方法是:
poetry config settings.virtualenvs.in-project true
配置保存在 ~/.config/poetry/config.toml 中。
这样再执行 poetry install
或者 poetry add
就会在项目目录下创建 .venv
子目录。
需要重新创建项目时,只要删除 .venv
文件夹并重新 poetry install
就行了。
Note: 用 poetry config --list
列出所有配置信息,
详细使用方法以及各配置项含义见
Configuration。