virtualenvwrapper.sh crashes shell

Question:

I am following the install instructions for virtualenvwrapper, described here.

I have used pip install virtualenvwrapper and it installed at the path /home/.pyenv/shims/.

But when I run the command
source /home/.pyenv/shims/virtualenvwrapper.sh the whole Konsole shuts down.
I had previously put the command in the .bashrc file and almost broke Linux because the Konsole would crash immediately after opening.

I’m using Linux OpenSuse and Python version 3.6.0.

Any ideas what could be causing the crash?

Asked By: berkelem

||

Answers:

I’m seeing the same thing on MacOS (10.12.6).

For me the .zshrc entry which closes/ends the terminal window is:

source $HOME/.pyenv/shims/virtualenvwrapper.sh

I also would like to know why this is occurring, and how to fix it.

Answered By: Alan W.

I have come across this problem several times now on different machines and while I don’t fully understand why it happens, I have found a solution to the problem.

The problem seems to be due to mismatches in the python version being used and the pip version used to install virtualenvwrapper. I had been using the system install of python (2.7) but the pip version was for python 3.5.

To fix this, use the suggestion in this answer as follows:

python -m pip install virtualenvwrapper

Then you can source /path/to/virtualenvwrapper.sh and everything should work fine.

Answered By: berkelem

I found a solution.

source ~/.pyenv/versions/VERSION/bin/virtualenvwrapper.sh works every time.

You can’t use the shims directory for some reason. Maybe since virtualenvwrapper was likely installed into the pyenv version directory. If you use the shims directory, that link could break when switching versions with pyenv. It’s better to access it directly.

Answered By: Sean Combs

Sean Combsanswer works for me, too. But I didn’t want to hard code a specific python version, so I use grep to build the path to virtualenvwrapper.sh dynamically.

export VIRTUALENVWRAPPER_PYTHON=$HOME/.pyenv/shims/python
source $HOME/.pyenv/versions/$($VIRTUALENVWRAPPER_PYTHON -V 2>&1 | grep -Po '(?<=Python )(.+)')/bin/virtualenvwrapper.sh
Answered By: Kevin Dalias

I had a same problem, and I solved it by installing virtualenvwrapper with builtin python(e.g. /usr/bin/python3), not a pyenv python runtime, though the builtin one is not used in actual workspaces.

Answered By: Snowso

To add to Sean’s answer since I don’t have enough reputation to add a comment, adding

export PYENV_VERSION="$(pyenv version-name)"
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh

to your .bashrc (or .zshrc in my case) allows you to point to the correct virtualenvwrapper.sh even if you change python versions without hardcoding or grep

Answered By: Penelope Clearwater

I had this problem on Mac and I found that zsh crashes
with line
source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh
if you not specified VIRTUALENVWRAPPER_PYTHON variable

So this’s my .zshrc (or .bashrc) config for pyenv and virtualenvwrapper on fresh user

command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

export PYENV_VERSION="$(pyenv version-name)"
VIRTUALENVWRAPPER_PYTHON="$HOME/.pyenv/shims/python"


export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel

source ~/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh

# Tell pyenv-virtualenvwrapper to use pyenv when creating new Python environments
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"

# Set the pyenv shims to initialize
if command -v pyenv 1>/dev/null 2>&1; then
 eval "$(pyenv init -)"
fi
Answered By: Mutiev Fedor