Link Search Menu Expand Document

Altair

Below are some additional info that can help with your Altair assignments:

Table of contents

Resources

Check the Altair documentation. Feel free to take inspiration from the Altair example gallery.

Optional setup instructions for larger/longer projects

These steps are only recommended if you plan to use JupyterLab often, for a larger project, or with collaborators.

Set up git to automatically clear metadata using JQ

  1. Install JQ by running, e.g.,

     sudo apt-get install jq
    

    For more options including your operating system check the JQ download site.

  2. Append the following block of code either in your local repo .gitconfig file or your global .gitconfig. I would recommend you do it in your global .gitconfig so you don’t need to redo that for future .ipynb files.

     [core]
     attributesfile = ~/.gitattributes_global
     [filter "nbstrip_full"]
     clean = "jq --indent 1 \
             '(.cells[] | select(has(\"outputs\")) | .outputs) = []  \
             | (.cells[] | select(has(\"execution_count\")) | .execution_count) = null  \
             | .metadata = {\"language_info\": {\"name\": \"python\", \"pygments_lexer\": \"ipython3\"}} \
             | .cells[].metadata = {} \
             '"
     smudge = cat
     required = true
    

    For more details look at this great tutorial here. You can use this command

     git config --list --show-origin --show-scope
    

    to find out where your git configuration is stored.

  3. Create a global gitattributes named .gitattributes_global file (usually placed at the root level, so ~/.gitattributes_global).

  4. Add the following line of code:

     *.ipynb filter=nbstrip_full
    

Jupyter Lab extensions

  • To get markdown section numbering use jupyterlab-toc.
    • To install run:

      jupyter labextension install @jupyterlab/toc
      
    • Then click the enumerated list button on the left strip in JupyterLab to bring up the table of contents. There you can click the itemized list button in the top to add section numbers to the markdown cells. ​

  • There is also a useful Spellchecker extension.

    • To install run:

      jupyter labextension install @ijmbarr/jupyterlab_spellchecker
      
  • To install both of the above with one (faster) command run:

      jupyter labextension install @jupyterlab/toc @ijmbarr/jupyterlab_spellchecker
    

Troubleshooting

Python issues

venv virtual environment issues

  • Are you in your virtual environment? Your command prompt / terminal prompt should be prefixed with (env) to show you that.

  • Are you using the python executable from your virtual environment?
    1. Check it!
      • On macOS or Linux, run:

          which python
        
      • On Windows, run:

          where.exe python
        

        Check the path(s) provided by which python or where.exe python — the first one listed should be inside the env folder you just created.

    2. If the first listed path is not inside the env folder you just created, then find a way to run the correct python executable.

  • Did you rename your env folder after creating it? If so, delete it and run the commands to create it again. venv uses hard-coded paths so renaming the folder is fraught.

Other pip install issues

  • You may get a warning like WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available. You should consuder upgrading... You don’t need to worry about fixing this.

  • You may run into issues where pip is using a different python than Jupyter Lab is running. E.g., you may install a package but then Jupyter complains it is unavailable. In that case:
    1. instead of pip install try running

       python -m pip install
      
    2. Additionally, check if python is from the same environment as pip:

      • On macOS or linux: which pip or which pip3 and which python

      • On Windows: where.exe pip or where.exe pip3 and where.exe python

  • You can also try installing the required packages without pinning to particular versions like we have done in requirements.txt. Do this by running:

      pip install -r requirements-noversions.txt
    

    You can also run the installs one-by-one to see if there are issues. E.g., pip install altair.

Windows issues

  • If you are using PowerShell (not the Command Prompt) and you get an error message saying the execution of scripts is disabled on this system, follow these steps.
    1. Open a new PowerShell as Administrator.
    2. Enable running unsigned scripts by entering

       set-executionpolicy remotesigned
      

      See the documentation for details.

  • If you get a NotImplementedError for asyncio while running Python 3.8, you may be able to resolve it by running

      pip install notebook --upgrade
    

    If not, edit /env/Lib/site-packages/tornado/platform/asyncio.py (instructions from here). Right after the line import asyncio add these lines:

      import sys
      if sys.platform == 'win32':
          asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    
  • If you get this error numpy.distutils.system_info.NotFoundError: no lapack/blas resources found try installing it manually. (Instructions modified from here.)

    1. In PowerShell or the Command Prompt CD to your repo folder, and enter your virtual environment.

    2. Download numpy+mkl wheel from one of the links here. Use the version that is the same as your Python version (check using python --version). E.g., if your Python is 3.6., download the wheel which shows cp36: numpy‑1.18.5+vanilla‑cp36‑cp36m‑win_amd64.whl. E.g., for Python 3.9.: numpy-1.19.2+mkl-cp39-cp39-win_amd64.whl

    3. Install the wheel (where numpy.whl is the file name you downloaded):

       pip install numpy.whl
      
    4. Likewise, download SciPy from one of the links here using the same version as your Python. E.g., for Python 3.6.: scipy‑1.5.3‑cp36‑cp36m‑win_amd64.whl. E.g., for Python 3.9.: scipy-1.5.3-cp39-cp39-win_amd64.whl

    5. Install the wheel (where scipy.whl is the file name you downloaded):

       pip install scipy.whl
      

Mac issues

  • When you run pip install -r requirements.txt, pip install numpy, or pip install scipy you may get this error: RuntimeError: Broken toolchain: cannot link a simple C program. Note that this error may be in the middle / end of a large error message. It means that Gcc is not available for compiling C programs (which Python is based on). Follow these steps:

    1. Try running

       brew help
      

      to see if you have Homebrew installed. If you get command not found, install Homebrew by running:

       /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
      
    2. Then run

       brew install gcc
      
    3. Try running this again:

       pip install -r requirements.txt
      

Altair issues

  • If you run into issues with Altair’s max rows limit, try reformatting the data before sending it to Altair. Alternatively use alt.data_transformers.enable('csv') in your notebook and make sure that altair-data-server is installed. It should be in your requirements.txt file already.

  • Read the relevant part of the Altair documentation.

  • Check the UW Visualization Curriculum debugging guide and the Altair FAQ for answers.

  • The developers of Altair sometimes release a new version via pip and update the documentation before it is stable. Note that the documentation version and Altair version you are using may be out of sync. (See the top-left of the documentation page for the version number, and in Jupyter Lab run alt.__version__ in a cell to see the Altair version). In this assignment, using the requirements.txt file we are asking you to install a particular version to avoid some issues like this.

General troubleshooting advice

  • Googling error messages is the best way to help you sort out weird issues with Python and Jupyter Lab.

  • You can also post a discussion topic on Canvas and we and other students will try to help!


© 2022 Cody Dunne. Released under the CC BY-SA license