配置文件
配置文件
文件路径
- macOS:
~/Library/Application Support/pypoetry/config.toml
- Windows:
C:\Users\<username>\AppData\Roaming\pypoetry\config.toml
可以通过
POETRY_CONFIG_DIR
环境变量来配置
# powershell
start $ENV:AppData\pypoetry\
# cmd
start "" %AppData%\pypoetry
查看配置
poetry config --list
修改配置
# 修改全局
poetry config virtualenvs.in-project true
# 修改项目本地
poetry config virtualenvs.in-project true --local
配置解释
cache-dir = "W:\\CPS\\python\\Poetry\\cache" # 配置缓存的下载目录,不想C盘臃肿的,这个必须配置
[virtualenvs]
create = true # 在各个项目下,是否始终使用虚拟环境
path = "{dir}" # 【重要】 这里要设置为 "{dir}",虚拟环境就会创建在项目的.env的文件夹中
in-project = true # 在项目目录创建虚拟环境
# prefer-active-python = true # 是否始终使用安装时的python版本
[virtualenvs.options]
no-pip = true # 生产环境中的虚拟环境,不生成pip
no-setuptools = true # 生产环境中的虚拟环境,不生成setup
system-site-packages = false # 是否通过system来访问全局的site-packages
always-copy = true # 确保虚拟环境的文件不是链接,这样可能会让整个项目非常大
[[tool.poetry.source]]
name = "tsinghua" # 源名称
url = "https://pypi.tuna.tsinghua.edu.cn/simple/" # 源地址
priority = "primary"
default = true
配置模板
cache-dir = "D:\\CPS\\python\\Poetry\\cache"
[virtualenvs]
create = true
prefer-active-python = true
always-copy = false
[virtualenvs.options]
no-pip = true
no-setuptools = true
system-site-packages = true
in-project = true
[[tool.poetry.source]]
name = "aliyun"
url = "http://mirrors.aliyun.com/pypi/simple"
priority = "primary"
源设置
常用源:
- 百度
https://mirror.baidu.com/pypi/simple
- 阿里云
http://mirrors.aliyun.com/pypi/simple/
- 豆瓣
https://pypi.douban.com/simple/
- 清华大学
https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学
http://pypi.mirrors.ustc.edu.cn/simple/
- 华中科技大学
http://pypi.hustunique.com/
[[tool.poetry.source]]
name = "tsinghua" # 源名称
url = "https://pypi.tuna.tsinghua.edu.cn/simple/" # 源地址
priority = "explicit" # 旧版使用default=true,表示当前项目使用这个源优先
[[tool.poetry.source]]
name = "aliyun"
url = "http://mirrors.aliyun.com/pypi/simple"
priority = "explicit"
命令行配置源
# 配置默认源
poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/
# 补充源
poetry source add --priority=supplemental mirrors https://pypi.tuna.tsinghua.edu.cn/simple/