<p>通过将<a href="https://pypi.org" rel="noreferrer">^{<cd1>}</a>和<a href="https://files.pythonhosted.org" rel="noreferrer">^{<cd2>}</a>设置为受信任主机,可以忽略SSL错误。</p>
<pre><code>$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
</code></pre>
<p><strong>注意</strong>:在2018年4月的某个时候,<a href="https://pypi.org" rel="noreferrer">Python Package Index</a>从<code>pypi.python.org</code>迁移到<code>pypi.org</code>。这意味着使用旧域的“受信任主机”命令不再工作。</p>
<h3>永久固定</h3>
<p>由于pip 10.0的发布,您应该能够通过升级<code>pip</code>本身来永久地修复这个问题:</p>
<pre><code>$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools
</code></pre>
<p>或者通过<a href="https://pip.pypa.io/en/stable/installing/" rel="noreferrer">reinstalling it</a>获取最新版本:</p>
<pre><code>$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
</code></pre>
<p>(…然后使用相关的Python解释器运行<code>get-pip.py</code>)。</p>
<p><code>pip install <otherpackage></code>应该在这之后工作。如果没有,那么您将需要做更多,如下所述。</p>
<hr/>
<p>你可能想<a href="https://pip.pypa.io/en/stable/user_guide/?highlight=appdata#config-file" rel="noreferrer">add the trusted hosts and proxy to your config file</a>。</p>
<p><code>pip.ini</code>(Windows)或<code>pip.conf</code>(unix)</p>
<pre><code>[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
</code></pre>
<hr/>
<p><strong>替代解决方案(不太安全)</strong></p>
<p>大多数答案都可能会带来安全问题。</p>
<p>帮助轻松安装大多数python包的两个解决方案是:</p>
<ul>
<li><strong>使用简易安装:如果您真的很懒,不想浪费太多时间,请使用<code>easy_install <package_name></code>。请注意,某些包将找不到或会出现小错误。</li>
<li><strong>使用控制盘:下载<a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="noreferrer">Wheel of the python package</a>,并使用pip命令<code>pip install wheel_package_name.whl</code>安装软件包。</li>
</ul>