Getting python installed on your computer


python.org

Install from python.org

Note: Navigate to python.org, select the Download option, and then choose the option that's right for your Operating System (OS)


Miniconda

Miniconda is a free minimal installer for conda. It [...] includes only conda, Python, the packages they depend on, and a small number of other useful packages [...].

  1. Click the 64-bit Python 3.9 version download link.
  2. Run the installer, accepting the license.
  3. Accept the defaults.

Miniconda Installer Links


Anaconda

Your data science toolkit [...] the open-source Individual Edition (Distribution) is the easiest way to perform Python/R data science and machine learning on a single machine.

Anaconda Individual Edition

Note: Anaconda or miniconda

Choose Anaconda if you:

  • Are new to conda or Python.
  • Like the convenience of having Python and over 1,500 scientific packages automatically installed at once.
  • Have the time and disk space---a few minutes and 3 GB.
  • Do not want to individually install each of the packages you want to use.
  • Wish to use a set of packages curated and vetted for interoperability and usability.
  • But beware, for enterprise editions, see pricing

Choose Miniconda if you:

  • Do not mind installing each of the packages you want to use individually.
  • Do not have time or disk space to install over 1,500 packages at once.
  • Want fast access to Python and the conda commands and you wish to sort out the other programs later.

A Note on different operating systems

Python is platform independant, you can install it on Windows, Mac or GNU/Linux. There are even versions of python for other platforms.


The need for a coding environment

the big plot

Note: To create this plot, we need to load data of different types (logs, maps, seismic), we then need to manipulate the data efficiently, and finally we need to plot it, for all this we use welly, numpy, matplotlib, and each have some dependencies.

We want to delegate the dependency management to a program, an environment manager. That is, a program that will check through all the installed packages (tools) you've installed and make sure all the versions are compatible.


conda, pyenv, virtualenv

We'll use conda in this tutorial but here is a nice Stack Overflow discussion of the options at your disposal.


Setting up an environment (1/2)

  1. Click on this link and leave the file in your Downloads folder: T22_getting_started/environment.yml

  2. Open an Anaconda Prompt from the Start menu, and type the following (all one line!):

conda env create -f %USERPROFILE%/Downloads/environment.yml

Note: For Mac and Linux users, simply save the environment.yml file in your Downloads folder, navigate to that folder in your terminal emulator and run conda env create (it will use environment.yml by default).


Setting up an environment (2/2)

  1. Hit return if it asks for confirmation. When finished, start the environment:

conda activate t22_setup

  1. Now one more step to get access to this environment from inside Jupyter (all one line again!):

python -m ipykernel install --user --name t22_setup


Adding to an environment

t22_setup is a bare-bones environment, you can add a <package> to it by running:

  • conda activate t22_setup

  • conda install <package>

  • pip install <package>

Note: The environment must be activated before installing new packages, install first from conda if the package is available there, then from pip if not. Unless the devs suggest otherwise.


jupyter

To start coding, run:

jupyter notebook

This will start a server and launch the notebook in your default browser:

the jupyter server

Note: Simply show whichever notebook instance I have running during demo.


Basic geoscience tool set

Let's open

environment.yml

to see what we installed.

Note: Open ./environment.yml inside the Jupyter notebook.


Choosing a text editor

To write code, well, you're going to need to write code! And because Python can be quite particular about formatting, you'll need a decent text editor.


Jupyter

The jupyter project provides the jupyter notebook environment:

the jupyter notebook

Note: We'll see this soon, but in here we can write formatted text, code, and have code outputs.


VSCode, Atom, Sublime Text

  • vscode: Code editing. Redefined.
  • vscodium: Open Source Binaries of VS Code
  • Atom: A hackable text editor for the 21st Century
  • Sublime Text: Text Editing, Done Right (but not free)

Note: It doesn't matter which you choose, as long as it works for you!


vi, vim, nano, emacs

The old school approach, but still totally valid:

Note: It doesn't matter which you choose, as long as it works for you!


Running Python

Python is a program installed on your computer, and it can be used in different ways, e.g.:

  • executing Python code in an interactive session
  • running a Python script directly from the operating system
  • in a Jupyter notebook, Binder instance, Google Colab, etc.

Note: we run Python from the command-line interface (CLI) either

  • (1) as a simple code editor for example to quickly check out a Python feature or
  • (2) as a script runner where we invoke Python from the CLI but pass a Python script to it to execute or
  • (3) in a notebook-like environment

NEXT: intro to Python notebook!