Python virtualenvwrapper初始化错误

时间:2012-05-29 22:03:15

标签: virtualenv virtualenvwrapper

重启机器后,我可以看到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 Lion, Python 2.7

1 个答案:

答案 0 :(得分:2)

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