The Python Ecosystem¶

Stats 507, Fall 2021

James Henderson, PhD
August 31, 2021

Python¶

  • Python is one of the most popular computing langauges.
  • It is used by both web developers and data scientists.
  • Python as a language is often characterized by its: readability, simplicity, and explicitness.

Python¶

  • Python is an interpreted (as opposed to a compiled) language.
  • Python is sometimes considered a "glue" language owing to its versatality.
  • Don't use the Python distributed with your OS.

Anaconda¶

  • Anaconda is a popular Python distrubution that comes with:
    • a package and environment manager conda
    • many preinstalled modules including: Pandas, Numpy, Scipy, IPython, and Jupyter.

Anaconda¶

  • Anacaonda Navigator provides graphical shortcuts to open instances of Jupyter Notebooks, Spyder, and other tools.

Environments¶

  • Environments allow us to isolate and manage dependencies
    • Environments can have different versions of key modules
    • ... or different versions of Python.
    • Clone your environment to backup before updating dependencies.
conda create --name 507b --clone 507

Conda Environments¶

  • To get started, in your terminal application, conda init.
  • Make sure conda is in your path.
  • venv is an alternative.

Managing environments¶

  • list conda env list
  • create conda create -n <env> python3.9
  • activate conda activate <env>
  • deactivate conda deactivate

Managing dependencies¶

  • Python modules (libraries) can be managed with conda.
  • conda install, conda update
  • "Channels" (e.g. conda-forge) are locations where conda will look for modules.
  • pip is the primary alternative.

IPython¶

  • IPython is an "interactive" Python interpreter.
  • IPython also provides the standard Python kernel for Jupyter notebooks.

IPython¶

[IPython] has become one of the most important tools in the modern Python data stack ... It encouarages an execute-explore workflow instead of the typical edit-compile-run workflow of many other programming langauges.

-- Wes McKinney

Spyder¶

  • Spyder is a GUI based IDE for Python.
  • Pairs a text editor with an IPython console for interactive use.
  • Offers linting, autocomplete, and other useful tools.
  • Spyder is a good place to edit and develop python scripts (.py).

Jupyter¶

  • Jupyter is an open-source project.
  • Provides software and services for interactive computing
  • Spun off from IPython in 2014

Jupyter Notebooks¶

  • Jupyter notebooks (.ipynb) are one of the most popular ways to share (and develop) data science.
  • Jupyter notebooks are browser-based and can be run from a local server or through a number of web-based services.
  • Support for many languages, but most popular with Python.

Console¶

  • You can use an interactive Python interpreter at the command line.
  • Most useful when working on a remote Linux server.
  • Be sure you are using the version of Python from your (conda) environment
    • ... and not the built-in version used by the OS.
  • Consider using IPython.

Command Line Text Editors¶

  • To edit scripts on remote servers, use a text editor.
  • Options: vim, emacs, nano, atom.
  • (I use emacs.)

Command Line Text Editors¶

  • When learning a new text editor start with:
    • How to quit/exit, e.g. emacs cntrl+x cntrl+c.
    • How to save edits, e.g. emacs cntrl+x cntrl+s.
    • Find a cheatsheet and keep it handy.
    • Learn a bit at a time, then let muscle-memory take over.
    • Supplement course materials with tutorials.

Text Editors¶

  • Text editors can also be useful on your own machine.
  • Can edit in Spyder or Jupyter, but may prefer a specialized tool.
  • Options: Visual Studio Code, Sublime Text.

Requirements¶

  • For most problem sets, you will be asked to submit:
    • a Jupyter notebook (.ipynb)
    • one ore more Python scripts (.py).
  • Occassionaly, may be asked to submit as .html or .md.
  • The jupytext library will be helpful here.

Suggestions¶

  • Use Spyder while focused on code.
  • Use VS code or another text editor when focused on markdown cells.
  • Use Jupyter to view and explore (and possibly develop).
  • You will be required to turn in .py source code for notebooks.

More suggestions¶

  • Use conda as your primary package manager.
  • Create an enviornment specific to this course ...
  • ... and clone to backup before new installs.
  • Take notes on the steps you take to solve a probelm in case you need to do it again (or help a peer).
  • Or keep a begining to end setup in a shell script.

Takeaways¶

  • There are many options for editing Python code and interacting with a Python interpreter.
  • Start simple, experiment, and use what works for you.