Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a virtual environment work with pyenv?

I'm trying to use QGIS, which requires python 3.6.x.

I'm on mac on a system that already has python 2.7 and 3.7.

I tried

brew update
brew install pyenv
brew install pyenv-virtualenv
pyenv install 3.6.5

It installs just fine. Then, when I try to activate

pyenv activate my-virtualenv

I get this error

Failed to activate virtualenv.

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

I tried again with

exec $SHELL
pyenv activate my-virtualenv

And received the same error.

I executed this command in bash-3.2$ and regular terminal

if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi

And I'm still getting the same error. How can I get an environment running that uses python 3.6?

like image 909
Snhorq Avatar asked Feb 10 '19 23:02

Snhorq


People also ask

How does Pyenv virtualenv work?

virtualenv allows you to create local (per-directory), independent python installations by cloning from existing ones. pyenv allows you to install (build from source) different versions of Python alongside each other; you can then clone them with virtualenv or use pyenv to select which one to run at any given time.

Can I use Conda with Pyenv?

conda integrates with pyenv and pyenv-virtualenv What is great about these environments is that we can create custom software environments to suit any project. We can install R packages, python modules, C/C++ executables, and more.


2 Answers

Try this: into the terminal,

  1. write: nano ~/.bashrc

  2. add in the end:

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  1. Exit and save
  2. into the terminal write: source ~/.bashrc

And it's all, this worked for me.

like image 88
Luis Avatar answered Oct 19 '22 18:10

Luis


Initialize pyenv:

exec $SHELL
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv activate my-virtualenv

To save yourself some typing add this to your .bashrc:

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
like image 44
phd Avatar answered Oct 19 '22 19:10

phd