Setup for Colab/Binder or Local Use#

This notebook will ensure that your coding environment is set up for the interactive activities in this textbook. You do not need to worry about these requirements if you are running code on the Dandihub. You can simply ignore this page and get on with the data!

Package Requirements#

If you’re not running the code on the Dandihub, then we have to ensure that your coding environment has all of the proper packages installed. The packages required are:

numpy==1.23.1
dandi==0.45.1
h5py==2.10.0

The code below will ensure that you have these packages or newer.

First, we need to ensure that you have the DANDI client installed in your coding environment. The cell below will try to import DANDI. If you have an old version of DANDI, it will prompt you to install a newer version. Type “Y” if you would like to install a new version (this is recommended). If you don’t have DANDI at all, it will install the most recent version.

# This will ensure that the correct version of dandi is installed
try:
    import dandi
    if dandi.__version__>='0.45.1':
        print('Updated DANDI installed.')
    else:
        response = input('Old version of DANDI installed. Would you like to install a newer version of DANDI? (Y/N)')
        if response.upper() == 'Y':
            !pip install --upgrade dandi
except ImportError as e:
    !pip install dandi 
Updated DANDI installed.

Next, we’ll check for pyNWB, the python package for NWB.

# Check for pywnb
try:
    import pynwb
    print('pyNWB installed.')
except ImportError as e:
    !pip install pwynb  
pyNWB installed.

Finally, also need to make sure you have the correct version of NumPy.

try:
    import numpy
    if numpy.__version__>='1.23.1':
        print('Updated NumPy installed.')
    else:
        response = input('Old version of NumPy installed. Would you like to install a newer version of NumPy? (Y/N)')
        if response.upper() == 'Y':
            !pip install --upgrade numpy
except ImportError as e:
    !pip install numpy
Updated NumPy installed.

First things first, let’s make sure you have the AllenSDK installed. See the Allen Institute website for information on installing it, otherwise, the cell below will do it for you.

# This will ensure that the AllenSDK is installed.
# If not, it will install it for you.
try:
    import allensdk
    if allensdk.__version__ == '2.13.6':
        print('allensdk already installed.')
    else:
        response = input('Old version of AllenSDK installed. Would you like to install a newer version? (Y/N)')
        if response.upper() == 'Y':
            !pip install --upgrade allensdk
except ImportError as e:
    !pip install allensdk
Collecting allensdk
  Using cached allensdk-2.15.1-py3-none-any.whl (4.0 MB)
Collecting psycopg2-binary
  Using cached psycopg2_binary-2.9.6-cp311-cp311-macosx_10_9_x86_64.whl (2.2 MB)
Collecting hdmf<=3.4.7
  Using cached hdmf-3.4.7-py3-none-any.whl (187 kB)
Requirement already satisfied: h5py in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (3.9.0)
Collecting matplotlib<3.4.3,>=1.4.3
  Using cached matplotlib-3.4.2.tar.gz (37.3 MB)
  Preparing metadata (setup.py) ... ?25l-
 \
 |
 done
?25hRequirement already satisfied: numpy in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (1.25.0)
Requirement already satisfied: pandas>=1.1.5 in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (2.0.3)
Requirement already satisfied: jinja2>=3.0.0 in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (3.1.2)
Requirement already satisfied: scipy<2.0.0,>=1.4.0 in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (1.11.1)
Requirement already satisfied: six<2.0.0,>=1.9.0 in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (1.16.0)
Collecting pynrrd<1.0.0,>=0.2.1
  Using cached pynrrd-0.4.3-py2.py3-none-any.whl (18 kB)
Collecting future<1.0.0,>=0.14.3
  Using cached future-0.18.3.tar.gz (840 kB)
  Preparing metadata (setup.py) ... ?25l-
 done
?25hRequirement already satisfied: requests<3.0.0 in /Users/ashley/anaconda3/envs/jb/lib/python3.11/site-packages (from allensdk) (2.31.0)
Collecting requests-toolbelt<1.0.0
  Using cached requests_toolbelt-0.10.1-py2.py3-none-any.whl (54 kB)
Collecting simplejson<4.0.0,>=3.10.0
  Using cached simplejson-3.19.1-cp311-cp311-macosx_10_9_x86_64.whl (75 kB)
Collecting scikit-image>=0.14.0
  Using cached scikit_image-0.21.0-cp311-cp311-macosx_10_9_x86_64.whl (12.9 MB)
Collecting scikit-build<1.0.0
  Using cached scikit_build-0.17.6-py3-none-any.whl (84 kB)
Collecting statsmodels<=0.13.0
  Using cached statsmodels-0.13.0.tar.gz (17.8 MB)
  Installing build dependencies ... ?25l-
 \
 |
 /
 -
 \
 |
 done
?25h  Getting requirements to build wheel ... ?25l-
 \
^C
?25h canceled
ERROR: Operation cancelled by user

Is there a more efficient way to run these checks? Just a requirements.txt file?