Python 虚拟环节最佳实践到底是啥?

2023-07-03 11:48:51 +08:00
 coolair
比如:我只想在每个项目目录下使用指定 Python 版本生成一个 venv 目录的虚拟环境,删除项目同时也删除虚拟环境。

不用为虚拟环境指定名词,不用把所有虚拟环境放在一个目录,删除项目了,环境还在。
1316 次点击
所在节点    问与答
12 条回复
maocat
2023-07-03 13:39:18 +08:00
pyenv
hsfzxjy
2023-07-03 13:40:55 +08:00
python 自带的 venv 库就好了
abersheeran
2023-07-03 13:48:02 +08:00
poetry 、pdm 之类的都有这个配置吧,可以把虚拟环境生成在项目内。
coolair
2023-07-03 13:50:49 +08:00
@hsfzxjy venv 不能指定 Python 版本。
coolair
2023-07-03 14:04:08 +08:00
@abersheeran poetry 、pdm 也不能指定 Python 版本。
xxxeeeex
2023-07-03 14:24:48 +08:00
用不同版本的 python 创建 venv ,python3.9 -m venv ,python3.8 -m venv
Trim21
2023-07-03 14:29:58 +08:00
@coolair 你要直接用对应版本的 python 来创建虚拟环境,不要用系统默认的那个 python
tqbfjotld
2023-07-03 14:31:46 +08:00
pyenv
Jirajine
2023-07-03 14:39:17 +08:00
https://github.com/mitsuhiko/rye
一个 rustup/cargo inspired Python 环境管理工具
fcfangcc
2023-07-03 17:25:04 +08:00
一圈用下来还是 pyenv 好用
abersheeran
2023-07-04 13:16:30 +08:00
@coolair poetry 很久没用了不知道,pdm 可以指定。
coolair
2023-07-04 14:23:42 +08:00
@abersheeran 我看了下,确实可以。但是需要安装所需版本,如果安装了多个 python 版本,那还不如直接用内置的 venv 。

At first, you need to choose a Python interpreter from a list of Python versions installed on your machine. The interpreter path will be stored in .pdm-python and used by subsequent commands. You can also change it later with pdm use.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/953617

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX