-
Notifications
You must be signed in to change notification settings - Fork 0
Python environments
We are currently transitioning from Python 2.7 to Python 3.5. Most lab projects (e.g. soundsig, zeebeez, songephys) are not yet Python 3 compatible, but we are working on it. For now, use Python 2.7 but try to write Python 3 compatible code.
The two preferred ways to manage Python packages are with anaconda (miniconda), or with virtualenv.
Python 2 and Python 3 come pre-installed on new versions of Ubuntu and Mac, and should already be on your workstations. If you choose to use anaconda or anaconda3 (Python 3 version), it will modify your bashrc so that you use an installation of Python that comes with anaconda (rather than your default system version).
conda create ENV_NAME
-
In the root directory of each project you work on, type
virtualenv env --python [python|python3]
to create a new environment inenv/
-
Activate the environment by running
source env/bin/activate
. This modifies your PATH to point to the virtualenv packages. Do this every time you need to install any packages or run any code, including starting a jupyter notebook.
conda install PKG
pip install PKG
Packages installed with pip with a virtualenv activated are installed in env/
and cannot be seen outside the env. Similarly, packages installed with pip outside the virtualenv cannot be seen inside the virtualenv.
To start with a blank slate, just delete the env/
directory and create a new environment.
Dependencies can be defined in a "requirements" file usually called requirements.txt
. Typically, it lists pypi packages with version numbers in the form PKG==VERSION
. It can also include references to git repositories and commit hashes to install from a repository.
Install from a requirements file:
pip install -r requirements.txt
Here are some of the common issues you may hit when trying to move from Python 2 to 3
The print statement print "hello"
has been replaced with the print function print("hello")
. Maintain 2 and 3 compatibility by adding from __future__ import print_function
and using the new syntax.
The division operator /
will do floating point division by default. What used to be 7 / 2 == 3
will now be 7 / 2 == 3.5
. In Python 3, integer (floor) division can be explicitly done with the //
operator, i.e. 7 // 2 == 3
. Maintain 2 and 3 compatibility by replacing any instance of integer division with //
and adding from __future__ import division
.
The old dict.items()
would return a list of tuples of (key, value) pairs. In python 3, it will return a dict_items
iterable. Iteration as for key, value in d.items()
will still work, but other things may break...?
xrange used to be a iterator version of range. Now, range is an iterator by default and xrange no longer exists. Just replace all usages of xrange with range.
Calendars and scheduling
Lab funds and purchases
Advising, Social Justice, Sexual Harassment, and Real World Shit
* Support ResourcesGetting connected to the lab network
Data storage and access
Computing
Working Remotely
Other Services
Husbandry, who to call, recordkeeping
Bird care links
Pecking Test (NAF 125)
Field Station
Certifications, protocols, techniques, and recipes
Instructions for individual pieces of equipment
Instructions
Hardware, software, and techniques for ephys
Data Collection
Data Analysis
Old pages:
- Webcam Notes
- Arduino Notes
- Pecking test computer configuration
- Troubleshooting (pecking test)
- Pumpkin's Sound Card
- Preparing Stimuli
Pages in progress: