virtualenvwrapper.sh crashes shell
Asked Answered
L

9

14

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?

Lactoprotein answered 24/10, 2018 at 14:32 Comment(0)
L
3

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.

Lactoprotein answered 17/6, 2019 at 10:25 Comment(0)
G
13

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.

Gide answered 24/1, 2021 at 1:19 Comment(3)
I have no such fileHypocotyl
@qaispak did you replace VERSION to your corresponding version like 3.9.1?Strongminded
This worked for me after changing the VERSION to my corresponding version. Thank you!Strongminded
B
5

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.

Bartolemo answered 20/3, 2019 at 13:53 Comment(3)
Did you find a solution to this? I have exactly the same problem on MacOS (10.15.1)Bet
I did not. I gave up on using virtualenvwrapper, and started using pipenv. I didn’t have the time to figure out what was going on, and went with a different tool.Bartolemo
Had the same issue, found this article very helpful: opensource.com/article/19/6/python-virtual-environments-mac. It helped me out at leastBurbage
L
3

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.

Lactoprotein answered 17/6, 2019 at 10:25 Comment(0)
Y
2

Sean Combs' answer 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
Yokel answered 28/7, 2021 at 22:41 Comment(1)
This worked for me. I did however have to adapt the dynamic grab of the current Python version so leaving this here in case it helps the next person: source $HOME/.pyenv/versions/$($VIRTUALENVWRAPPER_PYTHON -V 2>&1 | cut -d' ' -f2)/bin/virtualenvwrapper.shBurnell
D
2

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

Doggoned answered 18/10, 2022 at 0:16 Comment(0)
A
2

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
Accalia answered 7/1, 2023 at 10:36 Comment(0)
S
0

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.

Skate answered 30/9, 2022 at 6:0 Comment(0)
T
0

In your ~/.bashrc or ~/.zshrc, putting:

export PYENV_VERSION="$(cat $HOME/.pyenv/version)"
source "$HOME/.pyenv/versions/$PYENV_VERSION/bin/virtualenvwrapper.sh"

works for me.

Then answered 11/1, 2023 at 14:44 Comment(0)
C
0

I had this problem with ohmyzsh! on MacOS with pyenv installed using brew. I also use Warp but I don't think that's important.

If the ohmyzsh! virtualenvwrapper plugin is in your ~/.zshrc and this problem happens to you, zsh won't even start, which is bad news if zsh is your shell. Your best option is to open ~/.zshrc in a text editor and comment out the plugin - then you can open a zsh shell and either keep working without virtualenvwrapper or you can fix the issue.

As other posts have mentioned, this appears to have something to do with the version of virtualenvwrapper installed whichever Python installation you happen to be using.

The only solution I found was the following. It's a little heavy handed but it worked for me.

rm -rf ~/.pyenv
pyenv install 3.12.2 # Pick the version that you use the most
pip install virtualenvwrapper

In each directory that contains a virtual environment:

rm -rf .venv # Use the actual virtual environment directory

And rebuild the virtual environment

Concretion answered 18/5 at 15:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.