-
Notifications
You must be signed in to change notification settings - Fork 370
Setting up Python and getting to know Spyder
- Download the Anaconda Python distribution (we recommend the commandline version)
- Install Anaconda
- Follow these instructions to install Caiman here
Environments are a very useful Python feature. They make it easy to work with different versions of Python and Packages without interference (cheatsheet).
One can install packages with either conda or with pip. When software is available in each, it is preferable to use the version in conda, and use pip as a fallback option (as pip is not very aware of Conda). As an example:
conda install tifffile
Fetching package metadata .......
Solving package specifications: .
PackageNotFoundError: Package not found: '' Package missing in current osx-64 channels:
- tifffile
You can search for that package on anaconda.org with
anaconda search -t conda tifffile
If you can't find it in conda:
pip install tifffile
(if it is not available in conda or pip, you may need to manually install it)
This tells Python where to find installed packages if they're not installed in the standard (system) places. For example, to use CaImAn, we need to set this variable every time we launch a new shell or terminal:
export PYTHONPATH="/path/to/caiman:$PYTHONPATH"
Spyder is an interactive programming environment with several similarities to MATLAB. Spyder has an editor and an interactive shell. It also has an interface for debugging, inspectors for objects and documentation, and variable and folder explorers.
To launch Spyder, after activating your environment and updating the PYTHONPATH variable, type
spyder
Spyder will launch.
There are some settings you'll probably want to change after you launch it for the first time. Go to Preferences -> IPython Console -> Graphics and select Backend:Qt5. Restart Spyder. This will prevent inline figure plotting (displaying plots in a separate window).
Once launched, go to the editor and type
#%% DEFINES BLOCKS OF CODE
import numpy as np # math library
import scipy # scientific library
import pylab as pl # plotting library
#%% this will output some wisdom
print('Python and Calcium Imaging, a marriage made in heaven')
#%% this creates a random vector
a = np.random.random([10,10])
print(a)
#%% this will plot something
pl.imshow(a)
Each of the "#%%" defines a code block, similarly to cells (%%) in MATLAB. In order to run each of the cells press Control-Enter. If you want to run and then move to the next cell, press Control-Shift-Enter.