How can I make a virtual environment work with pyenv?
10,472
Solution 1
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 -)"
Solution 2
Try this: into the terminal,
write:
nano ~/.bashrc
add in the end:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
- Exit and save
- into the terminal write: source
~/.bashrc
And it's all, this worked for me.
Author by
Snhorq
Updated on July 18, 2022Comments
-
Snhorq almost 2 years
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 terminalif 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?
-
Snhorq about 5 yearsThat gets me Requirement already satisfied: setuptools in /Users/user/.pyenv/versions/3.6.5/envs/QGIS-virtualenv-3.6.5/lib/python3.6/site-packages Requirement already satisfied: pip in /Users/user/.pyenv/versions/3.6.5/envs/QGIS-virtualenv-3.6.5/lib/python3.6/site-packages
-
Snhorq about 5 yearsHow do I add something to
.bashrc
. What is the shell on mac? -
Snhorq about 5 years†he QGIS software comes in a .pkg. Now that I'm in my virtual environment,
(my-virtualenv) bash-3.2$
, how do I open the package just in the environment? -
phd about 5 yearsHow do I add something to .bashrc?
vim ~/.bashrc
. Orecho 'eval "$(pyenv init -)"' > ~/.bashrc
What is the shell on mac? I seebash-3.2
in your question, so I'm sure the shell isbash
. QGIS software comes in a .pkg. … how do I open the package just in the environment? No idea what is that pkg but it's certainly not a Python thing. -
Chris Larson about 5 yearsI think perhaps we may be missing a step in your actions here. You're telling me that executing
pyenv activate QGIS-virtualenv-3.6.5
immediately gives youRequirement already satisfied
without you taking any other action after typing that? Is that what you mean to say? -
Snhorq about 5 yearsThe pkg is a software called QGIS. Can I install software just to the virtual environment? I set up the environment because the software requires python 3.6
-
potench almost 3 yearsI ALSO had to add
eval "$(pyenv init --path)"
to get this working. So 3.zshrc
additions. -
phd almost 3 years@potench stackoverflow.com/a/68278214/7976758