我怎样才能修复我的virtualenv?

时间:2012-08-28 19:18:16

标签: python virtualenv osx-mountain-lion

我刚刚升级到OS X Mountain Lion,它杀死了我的大部分Python环境。我重新安装了分发0.6.28(python distribute_setup.py install --prefix ~/Library/Python/2.7/site-packages)&点头1.1(python setup.py install --prefix ~/Library/Python/2.7/site-packages)从头开始。然后我通过virtualenv安装了virtualenvwerapperpip而没有出错,但命令virtualenv ENVTEST失败的原因如下:

$ virtualenv ENVTEST
New python executable in TESTENV/bin/python
Please make sure you remove any previous custom paths from your /Users/x/.pydistutils.cfg file.
Installing setuptools.................done.
Installing pip....
Complete output from command /Users/csh401/TESTENV/bin/python /Users/x/TESTENV/bin/easy_install /Users/x/Librar...ort/pip-1.0.2.tar.gz:
/Users/x/TESTENV/bin/python: can't open file '/Users/x/TESTENV/bin/easy_install': [Errno 2] No such file or directory
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
  File "/Users/x/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.7.2', 'console_scripts', 'virtualenv')()
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 942, in main
    never_download=options.never_download)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 1054, in create_environment
    install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 654, in install_pip
    filter_stdout=_filter_setup)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 1020, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/x/.virtualenvs/env1/bin/python -x /Users/x/.virtu...nv1/bin/easy_install /Users/x/Librar...pport/pip-1.1.tar.gz failed with error code 2

我最好的猜测是,在我添加distribute参数之前,我无法安装pip--prefix。但是现在,当pip工作时,它并没有安装到正确的位置。

更新

pip安装了旧版本的virtualenv。我跑了pip install -U virtualenv,这顺便跑了。现在仍然出现错误,但是出现了不同的错误。

$ virtualenv -vvv TESTENV
Creating TESTENV/lib/python2.7
Symlinking Python bootstrap modules
  Symlinking TESTENV/lib/python2.7/config
  Symlinking TESTENV/lib/python2.7/lib-dynload
  Symlinking TESTENV/lib/python2.7/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking TESTENV/lib/python2.7/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking TESTENV/lib/python2.7/ntpath.py
  Symlinking TESTENV/lib/python2.7/genericpath.py
  Symlinking TESTENV/lib/python2.7/fnmatch.py
  Symlinking TESTENV/lib/python2.7/locale.py
  Symlinking TESTENV/lib/python2.7/encodings
  Symlinking TESTENV/lib/python2.7/codecs.py
  Symlinking TESTENV/lib/python2.7/stat.py
  Symlinking TESTENV/lib/python2.7/UserDict.py
  File TESTENV/lib/python2.7/lib-dynload/readline.so already exists
  Symlinking TESTENV/lib/python2.7/copy_reg.py
  Symlinking TESTENV/lib/python2.7/types.py
  Symlinking TESTENV/lib/python2.7/re.py
  Symlinking TESTENV/lib/python2.7/sre.py
  Symlinking TESTENV/lib/python2.7/sre_parse.py
  Symlinking TESTENV/lib/python2.7/sre_constants.py
  Symlinking TESTENV/lib/python2.7/sre_compile.py
  File TESTENV/lib/python2.7/lib-dynload/zlib.so already exists
  Symlinking TESTENV/lib/python2.7/warnings.py
  Symlinking TESTENV/lib/python2.7/linecache.py
  Symlinking TESTENV/lib/python2.7/_abcoll.py
  Symlinking TESTENV/lib/python2.7/abc.py
  Symlinking TESTENV/lib/python2.7/_weakrefset.py
Creating TESTENV/lib/python2.7/site-packages
Writing TESTENV/lib/python2.7/site.py
Writing TESTENV/lib/python2.7/orig-prefix.txt
Writing TESTENV/lib/python2.7/no-global-site-packages.txt
Creating parent directories for TESTENV/include
Symlinking TESTENV/include/python2.7
Creating TESTENV/bin
New python executable in TESTENV/bin/python
Changed mode of TESTENV/bin/python to 0755
MacOSX Python framework detected
Symlinking TESTENV/.Python
Testing executable with TESTENV/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
Got sys.prefix result: u'/Users/x/TESTENV'
Please make sure you remove any previous custom paths from your /Users/x/.pydistutils.cfg file.
Creating TESTENV/lib/python2.7/distutils
Writing TESTENV/lib/python2.7/distutils/__init__.py
Writing TESTENV/lib/python2.7/distutils/distutils.cfg
Using existing distribute egg: /Users/x/Library/Python/2.7/site-packages/virtualenv_support/distribute-0.6.27.tar.gz
Installing distribute...
  Running command /Users/x/TESTENV/bin/python -c "#!python
\"\"\"Bootstra... main(sys.argv[1:])
" -v --always-copy -U distribute
  Extracting in /var/folders/97/bds2slvx25s53xx1b_strvfs4xdq4b/T/tmpbqvjfq
  Now working in /var/folders/97/bds2slvx25s53xx1b_strvfs4xdq4b/T/tmpbqvjfq/distribute-0.6.27
  Installing Distribute
  running install
  Checking .pth file support in /Users/x/Library/Python/2.7/site-packages/
  /Users/x/TESTENV/bin/python -E -c pass
  TEST FAILED: /Users/x/Library/Python/2.7/site-packages/ does NOT support .pth files
  error: bad install directory or PYTHONPATH

  You are attempting to install a package to a directory that is not
  on PYTHONPATH and which Python does not read ".pth" files from.  The
  installation directory you specified (via --install-dir, --prefix, or
  the distutils default setting) was:

      /Users/x/Library/Python/2.7/site-packages/

  and your PYTHONPATH environment variable currently contains:

      ''

  Here are some of your options for correcting the problem:

  * You can choose a different installation directory, i.e., one that is
    on PYTHONPATH or supports .pth files

  * You can add the installation directory to the PYTHONPATH environment
    variable.  (It must then also be on PYTHONPATH whenever you run
    Python and want to use the package(s) you are installing.)

  * You can set up the installation directory to support ".pth" files by
    using one of the approaches described here:

    http://packages.python.org/distribute/easy_install.html#custom-installation-locations

  Please make the appropriate changes for your system and try again.
  Something went wrong during the installation.
  See the error message above.
...Installing distribute...done.
Installing existing pip-1.1.tar.gz distribution: /Users/x/Library/Python/2.7/site-packages/virtualenv_support/pip-1.1.tar.gz
Installing pip...
  Running command /Users/x/TESTENV/bin/python -x /Users/x/TESTENV/bin/easy_install /Users/x/Librar...pport/pip-1.1.tar.gz
  /Users/x/TESTENV/bin/python: can't open file '/Users/x/TESTENV/bin/easy_install': [Errno 2] No such file or directory
  Complete output from command /Users/x/TESTENV/bin/python -x /Users/x/TESTENV/bin/easy_install /Users/x/Librar...pport/pip-1.1.tar.gz:
  /Users/x/TESTENV/bin/python: can't open file '/Users/x/TESTENV/bin/easy_install': [Errno 2] No such file or directory
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
  File "/Users/x/bin/virtualenv", line 9, in <module>
    load_entry_point('virtualenv==1.7.2', 'console_scripts', 'virtualenv')()
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 942, in main
    never_download=options.never_download)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 1054, in create_environment
    install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 654, in install_pip
    filter_stdout=_filter_setup)
  File "/Users/x/Library/Python/2.7/site-packages/virtualenv.py", line 1020, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /Users/x/TESTENV/bin/python -x /Users/x/TESTENV/bin/easy_install /Users/x/Librar...pport/pip-1.1.tar.gz failed with error code 2

所以看起来我的PYTHONPATH在virtualenv试图构建的环境中被某种方式消除了。这应该很容易解决,对吧?

3 个答案:

答案 0 :(得分:2)

这是distutils的问题。我删除了$ HOME / .pydistutils.cfg并运行sudo setup.py install以在正确的位置分发,然后sudo setup virtualenv将其放入适用于MacPorts版本的Python 2.7的site-packages目录中。现在我可以毫无问题地运行virtualenv TestEnv

答案 1 :(得分:1)

在VPS和我的Mac上设置centos时遇到同样的问题。

我找到了解决方案,如果你在pip安装后没有导出一些代码就会出现。解决方案步骤是:

写命令行:哪个pip                      show:&#39; / usr / bin / pip&#39;像这样 然后在命令行上运行此代码:export PATH =&#34; / usr / bin:$ PATH&#34;

我希望这对你也有用

答案 2 :(得分:0)

我不确定,因为我没有测试过我的想法。

以下软件包代码,安装library at /x/lib/python2.x/site-packagesscripts at /x/bin

  

python setup.py install --prefix / x

所以你不应该做python setup.py install --prefix /x/lib/python2.x/site-packages

同时尝试查看脚本pipvirtualenv是否使用了正确的python二进制文件。脚本中的shebang会告诉你。如果不是,他们可能会使用不同的发行版。

#!/usr/local/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.1','console_scripts','pip'
__requires__ = 'pip==1.1'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('pip==1.1', 'console_scripts', 'pip')()
)

上述脚本是指包含位于/usr/local/bin/python的二进制文件的分发。

在系统上,你可以有多个python共存的发行版。