coolair
V2EX  ›  问与答

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

  •  
  •   coolair · Jul 3, 2023 · 2625 views
    This topic created in 1235 days ago, the information mentioned may be changed or developed.
    比如:我只想在每个项目目录下使用指定 Python 版本生成一个 venv 目录的虚拟环境,删除项目同时也删除虚拟环境。

    不用为虚拟环境指定名词,不用把所有虚拟环境放在一个目录,删除项目了,环境还在。
    12 replies  •  2023-07-04 14:23:42 +08:00
    maocat
    maocat
    Jul 3, 2023
    1
    pyenv
    hsfzxjy
    hsfzxjy
    Jul 3, 2023 via Android❤️1
    2
    python 自带的 venv 库就好了
    abersheeran
    abersheeran
    Jul 3, 2023
    3
    poetry 、pdm 之类的都有这个配置吧,可以把虚拟环境生成在项目内。
    coolair
    coolair
    OP
    Jul 3, 2023
    4
    @hsfzxjy venv 不能指定 Python 版本。
    coolair
    coolair
    OP
    Jul 3, 2023
    5
    @abersheeran poetry 、pdm 也不能指定 Python 版本。
    xxxeeeex
    xxxeeeex
    Jul 3, 2023
    6
    用不同版本的 python 创建 venv ,python3.9 -m venv ,python3.8 -m venv
    Trim21
    Trim21
    Jul 3, 2023
    7
    @coolair 你要直接用对应版本的 python 来创建虚拟环境,不要用系统默认的那个 python
    tqbfjotld
    tqbfjotld
    Jul 3, 2023
    8
    pyenv
    Jirajine
    Jirajine
    Jul 3, 2023
    9
    https://github.com/mitsuhiko/rye
    一个 rustup/cargo inspired Python 环境管理工具
    fcfangcc
    fcfangcc
    Jul 3, 2023
    10
    一圈用下来还是 pyenv 好用
    abersheeran
    abersheeran
    Jul 4, 2023
    11
    @coolair poetry 很久没用了不知道,pdm 可以指定。
    coolair
    coolair
    OP
    Jul 4, 2023
    12
    @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.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 22:19 · PVG 06:19 · LAX 14:19 · JFK 17:19
    ♥ Do have faith in what you're doing.