4

I already referred to this related post

I am currently using a jupyter notebook in my server (where I don't have sudo access) which has python 2.7 kernel.

However, I would like to add Python >= 3.5 as the kernel. So, I was using followed the tutorial to install Pyenv.

The installation is successful and I get the below message in my jupyter notebook

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by adding
# the following to ~/.bashrc:

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

Later, when I try to execute the below command, I get an error as shown below

!pyenv install --list | grep " 3\.[678]" 

Please note that I am using ! symbol as I am executing it from Jupyter notebook cell

/bin/sh: 1: pyenv: not found

How can I avoid this error and make pyenv work and produce the below output

enter image description here

The Great
  • 7,215
  • 7
  • 40
  • 128
  • this may [help change python interpreter for jupyter](https://stackoverflow.com/questions/58645807/change-interpreter-in-jupyter-notebook) – sahasrara62 Jun 22 '20 at 10:12
  • what's the result of your `echo $PATH`? Also, did you restart the shell `exec "$SHELL"` after adding path. – kHarshit Jun 22 '20 at 12:35
  • Here is the path `/home/abcd/bin:/home/abcd/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin` – The Great Jun 22 '20 at 12:39
  • How do I restart the shell `exec "$SHELL"`? – The Great Jun 22 '20 at 12:41
  • Acc to your $PATH, the pyenv wasn't added to it. Did you add the path in `.bashrc` ? You can also use `>> ~/.bashrc` after every export command. You may try using `!exec $SHELL` to reload shell. Maybe try doing these things from the command line itself. – kHarshit Jun 22 '20 at 13:08
  • I am sorry. Am new to Python and ubuntu.. May I check with you on how can I launch command line for commands? Meaning I am already in the ubuntu server. – The Great Jun 22 '20 at 13:11
  • I used `jupyter notebook` to launch the jupyter notebook. – The Great Jun 22 '20 at 13:11
  • Where can I find the `.bashrc`? – The Great Jun 22 '20 at 13:12
  • Okay, from the terminal where you use `jupyter notebook`, run the export commands by appending `>> .bashrc` to each one of them (or open `.bashrc` using any text editor and paste the commands). `.bashrc` will be at your `/home/username/`. – kHarshit Jun 22 '20 at 13:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/216432/discussion-between-the-great-and-kharshit). – The Great Jun 22 '20 at 13:15

1 Answers1

15

As per the discussion in comments section, it turns out the pyenv path wasn't exported to .bashrc. It can be done by executing the following commands in terminal:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc

then restart the shell

exec "$SHELL"

Now, you can use pyenv to create virtual environments, then activate the environment and start working without interfering with the system environment.

kHarshit
  • 11,362
  • 10
  • 52
  • 71