前言
-
技术栈
Windows 10 Python 3.8.10 Python 3.11.2 pip 23.0.1 pipx 1.2.0 poetry 1.4.1
-
Python 3.8 装置目录
C:\Python38
-
Python 3.11 装置目录
C:\Python311
装置 poetry
-
设置将以下门路退出
path
环境变量C:\Python38 C:\Python38\Scripts C:\Python311 C:\Python311\Scripts C:\Users\qbit\.local\bin\
-
复制文件
C:\Python38\python.exe -> C:\Python38\py38.exe C:\Python311\python.exe -> C:\Python38\py311.exe
-
设置 pip 国内镜像源
py38 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ py311 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
-
降级 pip
py38 -m pip install pip --upgrade py311 -m pip install pip --upgrade
-
装置或降级 pipx
py38 -m pip install pipx --upgrade py311 -m pip install pipx --upgrade
-
在 Python 3.11 下用 pipx 装置 Poetry
py311 -m pipx install poetry --force -i https://mirrors.aliyun.com/pypi/simple/
-
查看装置状况
> where poetry c:\Users\qbit\.local\bin\poetry.exe > poetry --version Poetry (version 1.4.1)
-
设置将虚拟环境目录放在我的项目内
poetry config virtualenvs.in-project true
测试多版本共享
测试 Python 3.11
-
创立空目录
F:\tmp\test311
,在外面创立文件pyproject.toml
,文件内容如下:[tool.poetry] name = "test" version = "0.1.0" description = ""authors = ["qbit"] readme = "README.md" [[tool.poetry.source]] name = "aliyun" url = "https://mirrors.aliyun.com/pypi/simple/" default = true [tool.poetry.dependencies] python = "^3.11" requests = "~2.28.2" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"
-
创立虚拟环境并装置第三方库
poetry update -vv
-
查看虚拟环境信息
> poetry env info Virtualenv Python: 3.11.2 Implementation: CPython Path: F:\tmp\test\.venv Executable: F:\tmp\test\.venv\Scripts\python.exe Valid: True System Platform: win32 OS: nt Python: 3.11.2 Path: C:\Python311 Executable: C:\Python311\python.exe
测试 Python 3.8
-
创立空目录
F:\tmp\test38
,在外面创立文件pyproject.toml
,文件内容如下:[tool.poetry] name = "test" version = "0.1.0" description = ""authors = ["qbit"] readme = "README.md" [[tool.poetry.source]] name = "aliyun" url = "https://mirrors.aliyun.com/pypi/simple/" default = true [tool.poetry.dependencies] python = "^3.8" requests = "~2.28.2" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"
-
切换 python 环境
poetry env use C:\Python38\python.exe
-
创立虚拟环境并装置第三方库
poetry update -vv
-
查看虚拟环境信息
> poetry env info Virtualenv Python: 3.8.10 Implementation: CPython Path: F:\tmp\test38\.venv Executable: F:\tmp\test38\.venv\Scripts\python.exe Valid: True System Platform: win32 OS: nt Python: 3.8.10 Path: C:\Python38 Executable: C:\Python38\python.exe
本文出自 qbit snap