前言
技术栈
Windows 10Python 3.8.10Python 3.11.2pip 23.0.1pipx 1.2.0poetry 1.4.1
Python 3.8 装置目录
C:\Python38
Python 3.11 装置目录
C:\Python311
装置 poetry
设置将以下门路退出
path
环境变量C:\Python38C:\Python38\ScriptsC:\Python311C:\Python311\ScriptsC:\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 --upgradepy311 -m pip install pip --upgrade
装置或降级 pipx
py38 -m pip install pipx --upgradepy311 -m pip install pipx --upgrade
在 Python 3.11 下用 pipx 装置 Poetry
py311 -m pipx install poetry --force -i https://mirrors.aliyun.com/pypi/simple/
查看装置状况
> where poetryc:\Users\qbit\.local\bin\poetry.exe> poetry --versionPoetry (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 infoVirtualenvPython: 3.11.2Implementation: CPythonPath: F:\tmp\test\.venvExecutable: F:\tmp\test\.venv\Scripts\python.exeValid: TrueSystemPlatform: win32OS: ntPython: 3.11.2Path: C:\Python311Executable: 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 infoVirtualenvPython: 3.8.10Implementation: CPythonPath: F:\tmp\test38\.venvExecutable: F:\tmp\test38\.venv\Scripts\python.exeValid: TrueSystemPlatform: win32OS: ntPython: 3.8.10Path: C:\Python38Executable: C:\Python38\python.exe
本文出自 qbit snap