PIP和virtualenv的麻烦

时间:2012-06-03 19:51:26

标签: python virtualenv pip

每当我在桌面上创建一个文件夹并在终端上运行“virtualenv venv”时,一切正常。但是,当我尝试在我的“文档”文件夹中创建一个文件夹并运行“virtualenv venv”时,我在下面收到此错误? 有什么建议吗?

Andrews-MacBook-Pro:Python Virtualenv AndrewParkPhotography$ cd myproject
Andrews-MacBook-Pro:myproject AndrewParkPhotography$ ls
Andrews-MacBook-Pro:myproject AndrewParkPhotography$ virtualenv venv
New python executable in venv/bin/python
Installing setuptools............done.
Installing pip...
  Error [Errno 2] No such file or directory while executing command /Users/AndrewParkPho...env/bin/easy_install /Library/Python/2.7/...pport/pip-1.1.tar.gz
...Installing pip...done.
Traceback (most recent call last):
  File "/usr/local/bin/virtualenv", line 8, in <module>
    load_entry_point('virtualenv==1.7.1.2', 'console_scripts', 'virtualenv')()
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 928, in main
    never_download=options.never_download)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 1042, in create_environment
    install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 640, in install_pip
    filter_stdout=_filter_setup)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 966, in call_subprocess
    cwd=cwd, env=env)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

1 个答案:

答案 0 :(得分:4)

在这里找到答案(Can't install via pip with Virtualenv

在没有空格的路径中创建virtualenv环境。这就是它发生的原因:

创建环境时,它会设置bin目录。在该bin目录中是与环境相关的所有可执行文件。有些是脚本。您可能知道,hashbang用于告诉系统使用哪个解释器来运行脚本。您可能经常在脚本的顶部看到这个:

#!/usr/bin/env python

如果脚本位于/tmp/test.py,则告诉系统运行此命令以执行脚本:

/usr/bin/env python /tmp/test.py

在你的情况下,virtualenv正在创建这样的脚本:

#!/tmp/oh no/bin/python

当系统尝试执行该操作时,它将尝试使用参数no / bin / python和/tmp/test.py执行命令/ tmp / oh。 / tmp / oh不存在,因此失败