Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyenv and anaconda issue with 'export PATH'

I have both pyenv+virtualenv and Anaconda installed in my system, to manage virtual enviroments.

My .zshrc file looks like this:

# Load pyenv automatically:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

# added by Anaconda3 4.2.0 installer
export PATH="$HOME/anaconda3/bin:$PATH"

In a given folder I set up a local pyenv virtual environment with

$ pyenv local test-env

Listing the pyenv virtual-envs within that folder results in:

$ pyenv versions
system
2.7.12
2.7.12/envs/test-env
* test-env (set by /home/<path>/.python-version)

But when I load python instead of opening a session with Python v2.7.12 (as one would expect since the pyenv virtual environment is loaded), I get:

$ python
Python 3.5.2 |Anaconda custom (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

So obviously the Anaconda platform is getting in between my pyenv virtual environment. Listing the conda environments shows:

$ conda-env list
# conda environments:
#
root                  *  /home/<user>/anaconda3

If I comment out the export PATH="$HOME/anaconda3/bin:$PATH" line, pyenv works as expected.

Is there any way to maintain both these managers without conflicting with each other?

like image 603
Gabriel Avatar asked Jan 23 '26 14:01

Gabriel


1 Answers

The answer was apparently buried in point 3 of the pyenv instructions Basic GitHub Checkout:

Please make sure eval "$(pyenv init -)" is placed toward the end of the shell configuration file since it manipulates PATH during the initialization

So the solution was to move that line to the end of the .zshrc file, like so:

# added by Anaconda3 4.2.0 installer
export PATH="$HOME/anaconda3/bin:$PATH"

# Load pyenv automatically:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
like image 112
Gabriel Avatar answered Jan 25 '26 05:01

Gabriel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!