V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
coolair
V2EX  ›  问与答

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

  •  
  •   coolair · 304 天前 · 1102 次点击
    这是一个创建于 304 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如:我只想在每个项目目录下使用指定 Python 版本生成一个 venv 目录的虚拟环境,删除项目同时也删除虚拟环境。

    不用为虚拟环境指定名词,不用把所有虚拟环境放在一个目录,删除项目了,环境还在。
    12 条回复    2023-07-04 14:23:42 +08:00
    maocat
        1
    maocat  
       304 天前
    pyenv
    hsfzxjy
        2
    hsfzxjy  
       304 天前 via Android   ❤️ 1
    python 自带的 venv 库就好了
    abersheeran
        3
    abersheeran  
       304 天前
    poetry 、pdm 之类的都有这个配置吧,可以把虚拟环境生成在项目内。
    coolair
        4
    coolair  
    OP
       304 天前
    @hsfzxjy venv 不能指定 Python 版本。
    coolair
        5
    coolair  
    OP
       304 天前
    @abersheeran poetry 、pdm 也不能指定 Python 版本。
    xxxeeeex
        6
    xxxeeeex  
       304 天前
    用不同版本的 python 创建 venv ,python3.9 -m venv ,python3.8 -m venv
    Trim21
        7
    Trim21  
       304 天前
    @coolair 你要直接用对应版本的 python 来创建虚拟环境,不要用系统默认的那个 python
    tqbfjotld
        8
    tqbfjotld  
       304 天前
    pyenv
    Jirajine
        9
    Jirajine  
       304 天前
    https://github.com/mitsuhiko/rye
    一个 rustup/cargo inspired Python 环境管理工具
    fcfangcc
        10
    fcfangcc  
       304 天前
    一圈用下来还是 pyenv 好用
    abersheeran
        11
    abersheeran  
       303 天前
    @coolair poetry 很久没用了不知道,pdm 可以指定。
    coolair
        12
    coolair  
    OP
       303 天前
    @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.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   776 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:37 · PVG 04:37 · LAX 13:37 · JFK 16:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.