Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
pyenv no longer sets paths correctly when activating virtual environments

I've been using pyenv for almost two years with no problems on my system running RHEL 8.3 (Linux kernel 4.18) with Gnome 3.32.2 in X11 mode. I primarily use the fish shell but also occasionally bash, both worked fine with pyenv until now. However, after running pyenv update about 24 hours ago, using the pyenv activate command to activate one of my created virtual environments no longer sets the path to use what I've installed in that virtual environment.

When I start a terminal session, I see a new message saying:

WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.

So I ran pyenv init which told me:

# Add pyenv executable to PATH by adding
# the following to ~/.profile:

set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths

# Load pyenv automatically by appending
# the following to ~/.config/fish/config.fish:

pyenv init - | source

# and the following to ~/.profile:

pyenv init --path | source

# If your ~/.profile sources ~/.config/fish/config.fish,
# the lines should be inserted before the part
# that does that.

# Make sure to restart your entire logon session
# for changes to ~/.profile to take effect.

I'm pretty sure I already have all of the above. Here's my ~/.profile:

set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
pyenv init --path | source

Here's my ~/.config/fish/config.fish:

# Set default editor
set -gx EDITOR nano

# Set Junest path
set PATH /home/[username]/.local/share/junest/bin $PATH

# Set pyenv root directory
set PYENV_ROOT $HOME/.pyenv

# Add pyenv and local bin to $PATH
set PATH $PYENV_ROOT/bin /home/[username]/.local/bin $PATH

# Add pyenv init to shell to enable shims and autocompletion 
# Note the command `pyenv init` will tell you to add this line for fish
status --is-interactive; and source (pyenv init -|psub)

pyenv init - | source

My ~/.bashrc:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific environment
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH

# Uncomment the following line if you don't like systemctl's auto-paging featur$
# export SYSTEMD_PAGER=

# User specific aliases and functions

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

A few more observations:

  1. I discovered that even though I have ~/.profile, it is never sourced/run when I log into my desktop environment.
  2. Putting set -Ux PYENV_ROOT $HOME/.pyenv and set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths in ~/.profile or ~/.config/fish/config.fish doesn't make a difference.

In the end, even after activating a pyenv-created virtual environment, I still don't have access to what's in it.

How can I troubleshoot this? Thank you.

over 4 years ago · Hanz Gallego
5 answers
Answer question

0

The message is wrong. ~/.profile is for posix-compatible shells, which fish is not, and so it won't read it. This should be reported as a bug in pyenv.

Now, you already have the code to add to $PATH in your config.fish, so it appears no further action from your end is necessary, the warning does not apply to you.

Your ~/.profile is fish-code, which is incompatible with shells that will read it and I suggest removing it.


If you didn't already have all the necessary bits:

Weirdly enough the actual code is fish-compatible (except for pyenv init --path, which prints posix code. I suggest just skipping it). Since it recommends using universal variables via set -U, and those persist, you'll just want to run the set -U once interactively:

set -Ux PYENV_ROOT $HOME/.pyenv
set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths

You do not want to add these in config.fish. Fish persists universal variables and this one adds to $fish_user_paths, so it will add one component every time you open a fish, which will just end up leaving you with hundreds of elements in it and slow down fish.

Alternatively add $PYENV_ROOT/bin to $PATH yourself in config.fish, just like the $PATH additions you're already doing:

# Set pyenv root directory
set -gx PYENV_ROOT $HOME/.pyenv
# (note that this must now come later because it uses $PYENV_ROOT)
set -gx PATH /home/[username]/.local/share/junest/bin $PYENV_ROOT/bin $PATH

(or use fish_add_path, shipped in fish 3.2 - fish_add_path /home/[username]/.local/share/junest/bin $PYENV_ROOT/bin - this will take care of not adding it multiple times)

Keep the pyenv init - | source (which ends up doing the same as source (pyenv init -|psub) without a useless temp file, so it's preferred)

over 4 years ago · Hanz Gallego Report

0

For those who have landed on this question and are using something other than fish, I also tried to follow the directions given by pyenv -init without success. Like @jmunsch, I have Ubuntu 20.04 and bash. However, it appears ~/.profile is either not being read or something in my bash configuration is overwriting the relevant ~/.profile settings before pyenv -init gets to run. No idea what this may be, but before anyone asks:

  1. Yes, the ~/.profile changes were set before the line that sources ~/.bashrc
  2. No, I don't use ~/.bash_profile or ~/.bash_login

Here's what I did instead, ALL in ~/.bashrc:

export PYENV_ROOT=$HOME/.pyenv
export PATH=$PYENV_ROOT/bin:$PATH
# <Other commands not relevant to pyenv - jump straight to evals if you like>
# .
# .
eval "$(pyenv init --path)"
eval "$(pyenv init -)"

I haven't tested pyenv exhaustively, but the warning has gone away and it seems to be functioning OK.

over 4 years ago · Hanz Gallego Report

0

OS: ubuntu 18.04

I updated pyenv by

pyenv update 

and it start showing this warning

WARNING: `pyenv init -` no longer sets PATH.
Run `pyenv init` to see the necessary changes to make to your configuration.

and pyenv no longer sets the path correctly

FIX

I have these lines in my ~/.bashrc . So, delete/comment these lines if you have in ~/.bashrc

export PATH="/home/yogi/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Add these lines in ~/.profile before sourcing ~/.bashrc

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"

Source profile

source ~/.profile
over 4 years ago · Hanz Gallego Report

0

Just replace the line eval "$(pyenv init -)" from your ~/.bashrc file to eval "$(pyenv init --path)".

Please refer this issue: https://github.com/pyenv/pyenv/issues/1906

over 4 years ago · Hanz Gallego Report

0

For Mac and fish, add this to ~/.config/fish/config.fish:

set PYENV_ROOT $HOME/.pyenv
set -x PATH $PYENV_ROOT/shims $PATH
set -x PATH $PYENV_ROOT/bin $PATH

if command -v pyenv 1>/dev/null 2>&1
    pyenv init - | source
end
over 4 years ago · Hanz Gallego Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!