<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PyPI &#8211; 李辉 / Grey Li</title>
	<atom:link href="https://greyli.com/tag/pypi/feed/" rel="self" type="application/rss+xml" />
	<link>https://greyli.com</link>
	<description>一个编程和写作爱好者的在线记事本</description>
	<lastBuildDate>Thu, 06 Nov 2025 11:36:11 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.26</generator>

<image>
	<url>https://greyli.com/wp-content/uploads/2025/03/avatar-500-compressed-144x144.jpg</url>
	<title>PyPI &#8211; 李辉 / Grey Li</title>
	<link>https://greyli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>从国内的 PyPI 镜像（源）安装 Python 包</title>
		<link>https://greyli.com/set-pypi-mirror/</link>
		<comments>https://greyli.com/set-pypi-mirror/#respond</comments>
		<pubDate>Wed, 27 Feb 2019 13:48:52 +0000</pubDate>
		<dc:creator><![CDATA[李辉]]></dc:creator>
				<category><![CDATA[计算机与编程]]></category>
		<category><![CDATA[pip]]></category>
		<category><![CDATA[Pipenv]]></category>
		<category><![CDATA[Poetry]]></category>
		<category><![CDATA[PyPI]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://greyli.com/?p=2365</guid>
		<description><![CDATA[不论是使用 pip，还是 Pipenv、Poetry等工具，安装 Python 包的时候会默认从官方的 PyP [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>不论是使用 pip，还是 Pipenv、Poetry等工具，安装 Python 包的时候会默认从官方的 PyPI 源下载文件，速度比较慢。国内的一些公司和机构提供了 PyPI 镜像源（mirror source），你可以设置让这些工具从国内的镜像源安装 Python 包，以便提高下载速度。</p>
<p>官方 PyPI 源的 URL 为 https://pypi.org/simple （旧的 URL 为 https://pypi.python.org/simple ），下面我们将以豆瓣提供的镜像源为例（URL 为 https://pypi.doubanio.com/simple/），介绍不同工具更改 PyPI 镜像源的方法：</p>
<h2>pip</h2>
<p>临时设置可以通过 -i 选项：</p>
<pre>$ pip install -i https://pypi.doubanio.com/simple/ flask</pre>
<p>全局设置有不同的层级和文件位置，以用户全局（per-user）为例，在 Linux &amp; macOS 中，配置需要写到 ~/.pip/pip.conf 文件中；Windows 中，配置文件位置为 %HOMEPATH%\pip\pip.ini，%HOMEPATH% 即你的用户文件夹，一般为“\Users\&lt;你的用户名&gt;”，具体值可以使用 echo %HOMEPATH% 命令查看。</p>
<p>通常你需要手动创建对应的目录和文件，然后写入下面的内容：</p>
<pre>[global]
index-url = https://pypi.doubanio.com/simple
[install]
trusted-host = pypi.doubanio.com
</pre>
<p>附注：按照 pip 文档，上面的配置文件位置是旧（legacy）的配置方式，但是因为比较方便设置，这里沿用了。新的建议是 Linux &amp; macOS 放到 $HOME/.config/pip/pip.conf，Windows 则放到 %APPDATA%\pip\pip.ini。具体可以访问 <a href="https://pip.pypa.io/en/stable/user_guide/#config-file、">pip 文档配置部分</a>查看。</p>
<h2>Pipenv</h2>
<p>类似 pip 的 -i （&#8211;index-url）选项，你可以使用 &#8211;pypi-mirror 临时设置镜像源地址：</p>
<pre>$ pipenv install --pypi-mirror https://pypi.doubanio.com/simple flask</pre>
<p>如果想对项目全局（per-project）设置，可以修改 Pipfile 中 [[source]] 小节：</p>
<pre>[[source]]

url = "https://pypi.doubanio.com/simple"
verify_ssl = true
name = "douban"</pre>
<p>另外一种方式是使用环境变量 PIPENV_PYPI_MIRROR 设置（Windows 系统使用 set 命令）：</p>
<pre>$ export PIPENV_PYPI_MIRROR=https://pypi.doubanio.com/simple</pre>
<p>你可以通过把这个环境变量的设置语句写入到终端的配置文件里实现“永久”设置，Linux &amp; macOS 可参考<a href="https://unix.stackexchange.com/questions/117467/how-to-permanently-set-environmental-variables">这里</a>，Windows 可参考<a href="https://www.howtogeek.com/51807/how-to-create-and-use-global-system-environment-variables/">这里</a>。</p>
<h2>Poetry / Flit</h2>
<p>因为 Poetry，Flit 这些工具遵循 PEP 518 创建了一个 pyproject.toml 文件来替代 setup.py、Pipfile 等配置文件，所以我们可以在这个文件里更改 PyPI 源。</p>
<p>使用 Poetry 时，在 pyproject.toml 末尾添加下面的内容来设置自定义镜像源：</p>
<pre>[[tool.poetry.source]]
name = "douban"
url = "https://pypi.doubanio.com/simple/"</pre>
<p>目前暂时没有其他方式，未来或许会为 poetry add 命令添加一个相关的设置选项。</p>
<p>同样的，Flit 大概要添加下面这些内容（未测试）：</p>
<pre>[[tool.flit.source]]
name = "douban"
url = "https://pypi.doubanio.com/simple/"</pre>
<h2>常用的国内 PyPI 镜像列表</h2>
<ul>
<li>豆瓣 https://pypi.doubanio.com/simple/</li>
<li>网易 https://mirrors.163.com/pypi/simple/</li>
<li>阿里云 https://mirrors.aliyun.com/pypi/simple/</li>
<li>清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/</li>
</ul>
<p>顺便提一下，使用镜像源需要注意一个问题：包的版本可能不会及时更新，遇到这种情况可以通过临时换回官方源解决。</p>
]]></content:encoded>
			<wfw:commentRss>https://greyli.com/set-pypi-mirror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
