2

重新启动我的机器后,当我的登录脚本调用它时,我可以看到 virtualenv 无法设置。

我的 .bashrc 包含

 export WORKON_HOME=~/.virtualenvs
 source /usr/local/bin/virtualenvwrapper.sh

错误看起来像

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/virtualenvwrapper/hook_loader.py", line 12, in <module>
    import optparse
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 77, in <module>
    import textwrap
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 32, in <module>
    class TextWrapper:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 74, in TextWrapper
    whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.

据我所知,错误消息中提到的项目看起来还不错,

ytestpythonapp$ls /Library/Python/2.7/site-packages/
README                                pip-1.1-py2.7.egg                     virtualenv.py                         virtualenv_support                    virtualenvwrapper-3.2-py2.7-nspkg.pth
easy-install.pth                      virtualenv-1.7.1.2-py2.7.egg-info     virtualenv.pyc                        virtualenvwrapper                     virtualenvwrapper-3.2-py2.7.egg-info

mytestpythonapp$ls /usr/local/bin/ | grep vir
virtualenv
virtualenvwrapper.sh

mytestpythonapp$echo $PATH
/Users/markdsievers/.virtualenvs/mytestpythonapp/bin:/usr/local/bin:/Users/markdsievers/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mongodb/bin:/usr/local/cmd:/usr/local/sbin:

我对 Python 还很陌生,但 virualenv 已经工作了几个星期,并且已经重启了很多次,所以我对这一切感到很困惑。任何指针都非常感谢。

OSX 狮子,Python 2.7

4

1 回答 1

2

您的基本目录中可能有一个与 python 模块名称冲突的文件,即 string.py

于 2012-05-29T23:16:16.353 回答