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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7658075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:31:29  来源:igfitidea点击:

virtualenvwrapper.sh error showing at terminal startup

pythonlinux

提问by kohrime

As I'm starting to learn Python programming, I installed virtualenvwrapper via these commands:

当我开始学习 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

I've been getting this error every time I open a terminal (via guake)

每次打开终端时我都会收到此错误(通过 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.

I'm using Linux Mint 10 64bit GNOME.

我正在使用 Linux Mint 10 64 位 GNOME。

Is there any way to solve this error I see in the terminal?

有什么办法可以解决我在终端中看到的这个错误?

I've tried searching via google but none of them seems to fix this problem.

我试过通过谷歌搜索,但似乎没有一个能解决这个问题。

Thank you in advance.

先感谢您。

===Edit===

===编辑===

This is what is written in /home/user/.bashrc

这是 /home/user/.bashrc 中写的

source /usr/local/bin/virtualenvwrapper.sh 2> /dev/null
VIRTUALENVWRAPPER_LOG_DIR=/tmp
export VIRTUALENVWRAPPER_LOG_DIR

Please help :(

请帮忙 :(

回答by John Keyes

You need to set the VIRTUALENVWRAPPER_LOG_DIRenvironment variable. Add this to your .bashrcfile:

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

VIRTUALENVWRAPPER_LOG_DIR=/tmp
export VIRTUALENVWRAPPER_LOG_DIR

回答by Aleksej

I've had a similar problem while trying to make it work on Debian. I needed to run it as a user other than the X user, but it used the ~/.virtualenvsdirectory of the X user for WORKON_HOME, VIRTUALENVWRAPPER_LOG_DIRand VIRTUALENVWRAPPER_HOOK_DIR.

我在尝试使其在 Debian 上运行时遇到了类似的问题。我需要以 X 用户以外的用户身份运行它,但它使用~/.virtualenvs了 X 用户的目录用于WORKON_HOME,VIRTUALENVWRAPPER_LOG_DIRVIRTUALENVWRAPPER_HOOK_DIR.

It works now that I set those variables to a proper directory in ~/.bashrc.

现在我将这些变量设置为~/.bashrc.

回答by x - y

For those who come afterwards, I had the same problem on Ubuntu 12 and solved this way:

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

  1. Switch to correct user:

    su username
    
  2. Make sure your WORKON_HOME variable is set to the path you want it to be (defaults to ~/.virtualenv)

    WORKON_HOME=$HOME/.virtualenv
    
  3. Then add these two lines before your source command:

    export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME"
    export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME"
    
  4. Then save and re-source your bashrc:

    source ~/.bashrc
    
  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
    

回答by rahmu

According to this, it seems to be an error with the APT package on Debian/Ubuntu/Mint.

据此,似乎是 Debian/Ubuntu/Mint 上的 APT 包错误。

I have installed virtualenvwrapper through APT first, then removed it and installed it via pip.

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

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

The APT package has added the file /etc/bash_completion.d/virtualenvwrapperbut didn't remove it. This is the file that's causing problems.

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

The recommended solution is to remove this file and the errors stop appearing. (Weirdly, simply renaming the file was not enough).

推荐的解决方案是删除此文件,错误将停止出现。(奇怪的是,仅仅重命名文件是不够的)。

回答by Lu.nemec

For complete removal under debian remove following:

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

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

That worked for me

那对我有用

Also delete files from python's dist-packages(depends on distro and python version)

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

回答by user2971029

Try and use the export command like this:

尝试使用这样的导出命令:

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

In my case, the hook.log was created in the same path that my virtualenvwrapper config where in /home/my_user/.virtualenvs, so what I did was to export the variable like this

在我的情况下,hook.log 是在与我的 virtualenvwrapper 配置相同的路径中创建的,在 /home/my_user/.virtualenvs 中,所以我所做的是像这样导出变量

$export VIRTUALENVWRAPPER_LOG_DIR = "./"

回答by Martlark

I had similar issues. I removed any settings in my ~/.bashrc related to virtualenv, eg:

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

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

That fixed the errors.

这修复了错误。