Skip to content

Instantly share code, notes, and snippets.

@entropiae
Last active July 7, 2024 09:46
Show Gist options
  • Save entropiae/326611addf6662d1d8fbf5792ab9a770 to your computer and use it in GitHub Desktop.
Save entropiae/326611addf6662d1d8fbf5792ab9a770 to your computer and use it in GitHub Desktop.
Install pyenv on Ubuntu 18.04 + Fish shell
Install pyenv on Ubuntu 18.04 + fish shell
- Install the packages required to compile Python
$ sudo apt-get update; sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
- Download pyenv code from github
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
- Define environment variable PYENV_ROOT to point to the path where pyenv repo is cloned
$ echo "set --export PYENV_ROOT $HOME/.pyenv" > ~/.config/fish/conf.d/pyenv.fish
- Add $PYENV_ROOT/bin to your $PATH for access to the pyenv command-line utility
$ set -U fish_user_paths $HOME/.pyenv/bin $fish_user_paths
- Add pyenv init to your shell to enable shims and autocompletion.
$ echo -e '\n\n# pyenv init\nif command -v pyenv 1>/dev/null 2>&1\n pyenv init - | source\nend' >> ~/.config/fish/config.fish
- Install pyenv-virtualenv
$ git clone https://github.com/pyenv/pyenv-virtualenv.git (pyenv root)/plugins/pyenv-virtualenv
- Enable virtualenv autocomplete
$ echo -e "\n# Enable virtualenv autocomplete\nstatus --is-interactive; and pyenv init - | source\nstatus --is-interactive; and pyenv virtualenv-init - | source\n" >> ~/.config/fish/conf.d/pyenv.fish
######################################
- List available Python versions
$ pyenv install --list
- Install a version
$ pyenv install 2.7.16
- Create a virtualenv
$ pyenv virtualenv 3.7.4 my_venv
- Activate a virtualenv
pyenv activate my_venv
@LukeDRussell
Copy link

Love your work, I've spent hours trying to get this working on my latest Fedora build.
Thanks so much.

@entropiae
Copy link
Author

@LukeDRussell I'm glad it helped! 😃

@antikytheraton
Copy link

Thanks bro. It was really helpful

@cs-lexliu
Copy link

Thanks for your sharing.
When I following your guide, I found that pyenv does not override the system python binary.
Here is the related issue link.
pyenv/pyenv#1906

You could replace the pyenv init - by pyenv init --path in line 16.
That can solve the problem.

@Margaux7
Copy link

Thanks!! It saved me.

@arcsector
Copy link

Amazing - thank you so much

@arcsector
Copy link

I'm on WSL and for some reason fish paths don't persist, so I had to add set -U fish_user_paths $HOME/.pyenv/bin $fish_user_paths to my ~/.config/fish/config.fish in order to get line 16 to work - other than that, fantastic!

@trumpyla
Copy link

Awesome!

@therealandreww
Copy link

Thanks so much!! Other tutorials made me reinstall WSL ㅠㅠ

@yf-1229
Copy link

yf-1229 commented Jul 4, 2023

Thanks to you, I got it!

@bryaneaton
Copy link

This still works great, i'm using arch btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment