终端启动时显示virtualenvwrapper.sh错误
我刚开始学习Python编程,按照这些命令安装了virtualenvwrapper:
# Install distribute: http://pypi.python.org/pypi/distribute
wget http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
# Install pip http://pypi.python.org/pypi/pip
sudo easy_install pip
# Install virtualenv
sudo pip install virtualenv
# Install virtualenvwrapper
sudo pip install --upgrade virtualenvwrapper
virtualenvwrapper.sh
echo source `which virtualenvwrapper.sh` >> $HOME/.bashrc
# IMPORTANT
# Go to the working directory
# Start a working environment virtualenv
mkvirtualenv <working environment name>
# Install all the requirements for the working environment
pip -E $VIRTUAL_ENV install -r requirements.txt
每次我打开终端(通过guake)时都会出现这个错误。
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/virtualenvwrapper/hook_loader.py", line 72, in main
backupCount=1,
File "/usr/lib/python2.6/logging/handlers.py", line 112, in __init__
BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python2.6/logging/handlers.py", line 64, in __init__
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
File "/usr/lib/python2.6/logging/__init__.py", line 827, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python2.6/logging/__init__.py", line 846, in _open
stream = open(self.baseFilename, self.mode)
IOError: [Errno 2] No such file or directory: '/home/ahim/$VIRTUALENVWRAPPER_LOG_DIR/hook.log'
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.
我使用的是Linux Mint 10 64位的GNOME系统。
有没有办法解决我在终端看到的这个错误呢?
我试着在谷歌上搜索,但似乎没有找到能解决这个问题的方法。
谢谢大家的帮助。
===编辑===
这是我在/home/user/.bashrc文件里看到的内容:
source /usr/local/bin/virtualenvwrapper.sh 2> /dev/null
VIRTUALENVWRAPPER_LOG_DIR=/tmp
export VIRTUALENVWRAPPER_LOG_DIR
请帮帮我 :(
7 个回答
2
我之前也遇到过类似的问题。我把我家目录下的.bashrc文件里跟virtualenv相关的设置都删掉了,比如:
# virtualenv
#export WORKON_HOME=~/virtualenvs
#source /usr/local/bin/virtualenvwrapper.sh
这样做之后,错误就解决了。
6
对于后来的朋友,我在Ubuntu 12上遇到了同样的问题,以下是我的解决方法:
切换到正确的用户:
su username
确保你的WORKON_HOME变量设置为你想要的路径(默认是~/.virtualenv)
WORKON_HOME=$HOME/.virtualenv
然后在你的source命令之前添加这两行:
export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME" export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
接着保存并重新加载你的bashrc文件:
source ~/.bashrc
16
根据这个链接,看起来这是在Debian/Ubuntu/Mint系统上APT包出现的一个错误。
我最开始是通过APT安装了virtualenvwrapper,然后又把它卸载了,接着用pip重新安装了一遍。
apt-get install virtualenvwrapper
apt-get remove virtualenvwrapper
pip install virtualenvwrapper
APT包安装时添加了一个文件,路径是/etc/bash_completion.d/virtualenvwrapper
,但是没有把它删除。这个文件就是导致问题的根源。
推荐的解决办法是删除这个文件,这样错误就不会再出现了。(奇怪的是,单纯重命名这个文件并不能解决问题)。