回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<h2>问题</h2>
<p>我最近在一些python项目上工作,遇到了很多问题,比如<code>pip</code>没有安装一些需求的最新版本。我在<code>osx</code>上,我用<a href="http://brew.sh/" rel="nofollow noreferrer">brew</a>安装<code>Python 2.7.6</code>。在我正在做的项目中,我们只是<code>pip install -r requirements.txt</code>。在当前情况下,我需要安装<code>argparse==1.2.1</code>。这是实际显示的最新版本<a href="https://pypi.python.org/pypi/argparse" rel="nofollow noreferrer">on the pypi website</a></p>
<p>这是我的输出</p>
<pre><code>Downloading/unpacking argparse==1.2.1 (from -r requirements.txt (line 4))
Could not find a version that satisfies the requirement argparse==1.2.1 (from -r requirements.txt (line 4)) (from versions: 0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 1.0.1, 1.0, 1.1)
Some externally hosted files were ignored (use --allow-external to allow).
Cleaning up...
No distributions matching the version for argparse==1.2.1 (from -r requirements.txt (line 4))
</code></pre>
<p>我对不同类型的需求也有类似的问题,比如我手动安装的<code>matplotlib</code>,如<a href="https://stackoverflow.com/a/4781684/1092815">here</a>。</p>
<p>如您所见,我的mac上的pip只有那些argparse版本:<code>0.1.0, 0.2.0, 0.3.0, 0.4.0, 0.5.0, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 1.0.1, 1.0, 1.1</code></p>
<h2>尝试修复</h2>
<p>我尝试用<code>brew reinstall python</code>重新安装python,然后还尝试用一些xargs magic:<code>pip freeze | xargs -I {} sudo pip install {} --upgrade --force-reinstall</code>重新安装我安装的所有python包。</p>
<p>在尝试重新安装所有程序包时,我遇到了大多数程序包的问题:<code>error: invalid command 'egg_info'</code>。我发现我有一个旧的<code>setuptools</code>所以我现在可以重新安装所有的东西,但是仍然存在<code>argparse</code>的问题。argparse也有同样的问题。</p>
<p>我让一个刚安装osx的朋友<code>pip install argparse</code>,他得到了<code>1.1</code>,所以我设置了一个<code>precise32</code><a href="http://www.vagrantup.com/" rel="nofollow noreferrer">vagrant box</a>来安装一个干净的带有<code>python-dev</code>+<code>libevent-dev</code>的ubuntu,安装<code>argparse==1.2.1</code>完全没有问题。</p>
<h2>温度修正</h2>
<p>为了继续进行这个项目,我在osx上安装了argparse 1.1,它似乎可以很好地满足我的工作。</p>
<h2>问题</h2>
<p>我对pypi还不是很在行,但是有什么原因我不能在pypi上显示最新的版本吗?听起来并不是pypi上的所有lib都可用于osx。有没有办法知道不同操作系统的版本可用性?</p>
<h2>编辑:内部解决方案</h2>
<p>argparse<code>1.1</code>似乎与此输出上显示的<code>1.2.1</code>相同</p>
<pre><code>vagrant@precise32:~$ python
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> argparse.__version__
'1.1'
>>> quit()
vagrant@precise32:~$ pip freeze | grep argparse
argparse==1.2.1
</code></pre>
<p>我试图在osx上使用<code>--allow-external</code>,但没有意识到它再次需要包的名称。</p>
<pre><code>sudo pip install argparse --allow-external argparse --upgrade
</code></pre>
<p>然后说:)</p>
<pre><code>argparse an externally hosted file and may be unreliable
Downloading/unpacking argparse from http://argparse.googlecode.com/files/argparse-1.2.1.tar.gz#md5=2fbef8cb61e506c706957ab6e135840c
Downloading argparse-1.2.1.tar.gz (69kB): 69kB downloaded
</code></pre>
<p>正如彼得所指出的,pip的最新版本<code>default to disallowing externally hosted files</code>。</p>