回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我用<code>virtualenvwrapper</code>创建一个虚拟环境,然后尝试用<code>pip</code>在其中安装django。但是,由于python版本中的冲突,我一直得到一个错误。在</p>
<pre><code>$ mkvirtualenv env
$ workon env
$ pip install django
Downloading/unpacking django
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/basecommand.py", line 134, in main
status = self.run(options, args)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/commands/install.py", line 236, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/req.py", line 1085, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/index.py", line 201, in find_requirement
page = self._get_page(main_index_url, req)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/index.py", line 554, in _get_page
return HTMLPage.get_page(link, req, cache=self.cache)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/index.py", line 671, in get_page
resp = urlopen(url)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/download.py", line 176, in __call__
response = self.get_opener(scheme=scheme).open(url)
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/download.py", line 238, in get_opener
headers.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(("User-agent", build_user_agent()))
File "/Users/mingot/virtualenvs/env/lib/python2.7/site-packages/pip/download.py", line 35, in build_user_agent
_implementation = platform.python_implementation()
File "/Users/mingot/soft/anaconda/lib/python2.7/platform.py", line 1486, in python_implementation
return _sys_version()[0]
File "/Users/mingot/soft/anaconda/lib/python2.7/platform.py", line 1451, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: '2.7.5 (default, Aug 25 2013, 00:04:04) \n[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]'
</code></pre>
<p>在系统中,我运行的是python anaconda:</p>
^{pr2}$
<p>并且<code>$PATH</code>被设置为</p>
<pre><code>/Users/mingot/soft/anaconda/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/opt/X11/bin
</code></pre>
<p>在虚拟环境中,python版本是:</p>
<pre><code>(env)$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
</code></pre>
<p>以及<code>$PATH</code>:</p>
<pre><code>/Users/mingot/virtualenvs/env/bin:/Users/mingot/soft/anaconda/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/opt/X11/bin
</code></pre>
<p>我知道问题是,在虚拟环境中,当执行非anaconda python2.7.5时,它仍然使用anaconda库中的<code>platforms.py</code>,导致正则表达式的求值崩溃,如建议的<a href="https://github.com/ContinuumIO/anaconda-issues/issues/33">here</a>。我不关心在虚拟环境中使用哪个python版本。关于如何告诉python在虚拟环境中使用正确的<code>platforms.py</code>有什么建议吗?在</p>
<p>谢谢!在</p>