virtualenvwrapper.sh错误显示在终端启动时

时间:2011-10-05 07:33:54

标签: python linux

当我开始学习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 个答案:

答案 0 :(得分:16)

According to this,Debian / Ubuntu / Mint上的APT包似乎有误。

我先通过APT安装了virtualenvwrapper,然后将其删除并通过pip安装。

apt-get install virtualenvwrapper
apt-get remove virtualenvwrapper
pip install virtualenvwrapper

APT包已添加文件/etc/bash_completion.d/virtualenvwrapper但未将其删除。这是导致问题的文件。

建议的解决方案是删除此文件,并且错误停止显示。 (奇怪的是,简单地重命名文件是不够的。)

答案 1 :(得分:6)

对于那些之后来的人,我在Ubuntu 12上遇到了同样的问题,并以这种方式解决了:

  1. 切换到正确的用户:

    su username
    
  2. 确保您的WORKON_HOME变量设置为您希望的路径(默认为〜/ .virtualenv)

    WORKON_HOME=$HOME/.virtualenv
    
  3. 然后在源命令之前添加这两行:

    export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME"
    export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
    
  4. 然后保存并重新发送您的bashrc:

    source ~/.bashrc
    

答案 2 :(得分:2)

我有类似的问题。我删除了与virtualenv相关的〜/ .bashrc中的所有设置,例如:

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

修正了错误。

答案 3 :(得分:1)

要在debian下完全删除,请删除以下内容:

/usr/local/bin/virtualenvwrapper*
/etc/bash_completion.d/virtualenvwrapper

这对我有用

还删除python的 dist-packages 中的文件(取决于发行版和python版本)

答案 4 :(得分:0)

您需要设置VIRTUALENVWRAPPER_LOG_DIR环境变量。将其添加到您的.bashrc文件中:

VIRTUALENVWRAPPER_LOG_DIR=/tmp
export VIRTUALENVWRAPPER_LOG_DIR

答案 5 :(得分:0)

我试图让它在Debian上运行时遇到了类似的问题。我需要以X用户以外的用户身份运行它,但它使用了~/.virtualenvsWORKON_HOMEVIRTUALENVWRAPPER_LOG_DIR的X用户的VIRTUALENVWRAPPER_HOOK_DIR目录。

现在我可以将这些变量设置为~/.bashrc中的正确目录。

答案 6 :(得分:0)

尝试并使用如下导出命令:

$export VIRTUALENVWRAPPER_LOG_DIR = "/path/to/the/hook.log"

就我而言,hook.log是在我的virtualenvwrapper在/home/my_user/.virtualenvs中配置的路径中创建的,所以我所做的就是导出这样的变量

$export VIRTUALENVWRAPPER_LOG_DIR = "./"
相关问题