Skip to content

Instantly share code, notes, and snippets.

@berend
Last active August 9, 2021 19:30
Show Gist options
  • Save berend/5836873b1839ed0a349829dcf7967d75 to your computer and use it in GitHub Desktop.
Save berend/5836873b1839ed0a349829dcf7967d75 to your computer and use it in GitHub Desktop.

Installing python on a (more or less) fresh linux mint 20

Do not's

  • do not use system python (unless to install something to get a better python)
  • do not use deasnakes PPA (just system python, but with backports and older versions)

If you use one of these, you don't have a proper pip installed and you get all sorts of problems with pip & virtualenvs

Do's

do use pyenv (most convenient via install here: https://github.com/pyenv/pyenv-installer

$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

Check where pyenv was installed, start in your home dir

  $ find . -name pyenv
  ./.pyenv/libexec/pyenv
  ./.pyenv/bin/pyenv

Then add that to your path (this should also persisted in your .bashrc - or similar)

  $ export PATH=$PATH:./.pyenv/bin/pyenv

you need zlib dev headers and some more

  $ sudo apt-get install -y zlib1g-dev libbz2-dev libsqlite3-dev libffi-dev libreadline-dev libssl-dev

then use pyenv to install the latest stable version, as of writing this - it is 3.9.6

  $ pyenv install 3.9.6

now setup that correctly.

  $ pyenv global 3.9.6
  $ pyenv versions
    system
  * 3.9.6 (set by /home/berend/.pyenv/version)

Then check python and pip

  $ pyenv which python
  /home/berend/.pyenv/versions/3.9.6/bin/python
  $ pyenv which pip
  /home/berend/.pyenv/versions/3.9.6/bin/pip

Put the bin path into your PATH environment variable, so that python and pip are found. This should also be done in .bashrc.

  $ export PATH=$PATH:~/.pyenv/bin:~/.pyenv/versions/3.9.6/bin

Now, setup virtualenv and virtualenvwrapper:

  $ pip install virtualenvwrapper

and add this to your .bashrc

  source ~/.pyenv/versions/3.9.6/bin/virtualenvwrapper.sh

Now check, if everything is installed properly:

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