pyenv-virtualenv initialisation failing.

Created on 7 Jul 2014  路  19Comments  路  Source: pyenv/pyenv-virtualenv

When running $ eval "$(pyenv virtualenv-init -)", I always get this error message:

Failed to deactivate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

For some reason, I can still use it on the same shell I installed it in, but not any other shell. How do I load up pyenv-virtualenv properly? Note: I Installed it using Homebrew.

I just realised I have issues with my virtualenv:

$ python
-bash: /Users/ncopty/.pyenv/versions/finprod/bin/python: No such file or directory
$ ~/.virtualenvs/finprod/bin/python
Python 2.7.2 (default, Jul  2 2014, 14:30:17) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.34.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Which one is the correct one and why do I have two?

Most helpful comment

You did the same mistake that I did. You also need eval "$(pyenv init -)" before the virtualenv-init

All 19 comments

I figured it out. The issue is that I had the initialisation set in .bash_profile. It needs to be set in .bashrc in Mac OS X if it one maintains both configs separately. I'll add a pull request with changes to the README.

Not completely. Now I can create a virtualenv and list it. But I cannot activate one using pyenv. When activating, I get:

Failed to deactivate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

Any ideas how to fix/debug? I removed all instances of virtualenv that I had installed manually, I re-installed this package using brew. The output of declare -f pyenv is empty.

I still have a shell that somehow still works (declare -f shows virtualenvwrapper there which is what I had before). But the newer shells I started up and did this clean up and re-installation with don't work. The way I'm working now using that old shell but I need to be able to get it working from a fresh new shell.

Have same here. Why did you close issue? Found a workaround?

@silvansky Yes. How did you install pyenv and pyenv-virtualenv? Also paste anything you've added to your bash_profile related to the, here.

I used the instructions from README, installed via brew and added eval "$(pyenv virtualenv-init -)" in .zshenv.

You did the same mistake that I did. You also need eval "$(pyenv init -)" before the virtualenv-init

Wow! I wish this info was in README... Thanks a lot!

@nayefc Thanks so much for that comment! I'd been editing and removed eval "$(pyenv init -)"!

Thanks @nayefc This bug take me 30m to solve

My PR adds @nayefc's tip to README.

I am getting the same error when I am trying to activate in fish shell, but working fine in bash.

Also, when I am trying to activate using direct command activate.fish, I am getting this error -

The file '.pyenv/versions/my_project/bin/activate.fish' is not executable by this user

How can I make it working in fish shell

Same error as @ankitjain87 here.

@ankitjain87 and @Githeo If you haven't already given up I was able to get fish working by adding

status --is-interactive; and source (pyenv init -|psub)
status --is-interactive; and source (pyenv virtualenv-init -|psub)

If you installed pyenv-virtualenv using Homebrew.

To my fish config.
~/.config/fish/config.fish

Thanks @bradleyhurley, it works!
I hope your trick will be included in the doc.

I'm still getting this issue. Any fix / work-around?

I was having trouble activating virtual environments due to same error mentioned in the original post.
Adding the following to .zshrc worked for me.

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

@imedmar -- THANK YOU!!

@nayefc Thank you!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

woshihuangshuai picture woshihuangshuai  路  5Comments

marshallpierce picture marshallpierce  路  7Comments

Insoleet picture Insoleet  路  3Comments

jackmaney picture jackmaney  路  7Comments

oblitum picture oblitum  路  11Comments