Skip to content

Instantly share code, notes, and snippets.

@dansondergaard
Last active August 11, 2020 07:40
Show Gist options
  • Save dansondergaard/5ac7478ce5d467ac4e08213429047685 to your computer and use it in GitHub Desktop.
Save dansondergaard/5ac7478ce5d467ac4e08213429047685 to your computer and use it in GitHub Desktop.

Instructions for setting up Python for both using Python-based applications and developing such applications yourself. Instructions are for mac OS only.

These are mostly notes for myself.

Install pyenv

This will install pyenv and set the global interpreter (not the system interpreter) to a reasonably recent Python version.

$ curl https://pyenv.run | bash
$ exec $SHELL

Then fetch a list of all available Python versions:

$ pyenv install --list

Pick one (at least 3.6.0) and run:

$ pyenv install <your chosen version>
$ pyenv global <your chosen version>

Verify that the global Python is now the version you chose:

$ python --version

Update pip to the newest version:

$ python -m pip update pip

Note that you can even use pyenv to install Conda!

Install pipx

$ python3 -m pip install --user pipx
$ python3 -m pipx ensurepath

To install a program and make it available globally:

$ pipx install <programs you use>

This will install each program in its own virtual env so they're completely separate and won't ruin your system's Python distribution.

Configure pip

Create the file $HOME/.pip/pip.conf and put this in it:

[global]
require-virtualenv = true

This will not disallow pip to install packages outside of a virtual environment. To install packages globally, use pipx.

Create environments for development

Create a new environment with a specific Python version:

$ pyenv virtualenv <python version> <env name>

You can now activate whenever you wish:

$ pyenv activate <env name>
$ # do you work
$ pyenv deactivate

To get rid of an environmet:

$ pyenv uninstall <env name>

Testing with different Python versions

The awesome Nox library will automatically pick up different Python versions installed with pyenv.

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