Installing Python and oTree

Posted by Junjie Ren on May 25, 2021

This is a simple log of how I install Python and oTree.

I use Anaconda, “a distribution of the Python and R for scientific computing, that aims to simplify package management and deployment”. First, create a new virtual environment named “otree” (or whatever), in which we will install oTree later, to separate from the default “base” environment:

1
$ conda create --name otree

This new environment has no package installed.

Activate “otree” environment:

1
$ conda activate otree

Install pip inside “otree” to install oTree later, as oTree is not available from conda.

1
$ conda install pip

Then, pip and some of its dependencies will be installed.

Alternatively, we can create the environment with pip installed using a single command:

1
$ conda create -n otree pip

To exit the current environment and get back to the base environment, we could execute

1
$ conda deactivate

Then we install oTree in the “otree” environment. First enter the “otree” environment:

1
$ conda activate otree

Then use pip to install oTree:

1
$ pip3 install -U otree

Run oTree

It seems that the following command

1
$ /Applications/Python\ 3.9/Install\ Certificates.command

is undoable (or unnecessary?) if we are running oTree in a virtual environment rather than the default environment of our system. (If you downloaded Python from its official website, this command should probably be a step of the installation.)

Then go to wherever you’d like to put your oTree project

1
$ cd some_path

and create your project:

1
$ otree startproject myproject

It asks you

1
Include sample games? (y or n):

Type either y or n and then it shows

1
2
Created project folder.
Enter "cd myproject" to move inside the project folder, then start the server with "otree devserver".

Therefore,

1
2
$ cd myproject
$ otree devserver

Then we can visit the demo site at http://localhost:8000/. To stop the server, press ⌃ Control + C at the command line.

A tip

After installing Anaconda, when we restart the Terminal, there would be a “(base)” appearing in front of Terminal prompt looking like:

1
(base) $

This is because conda’s base environment is activated on startup. To disable it, type

1
$ conda config --set auto_activate_base false

and restart Terminal. Then every time we open Terminal, the conda environment will not be activated automatically and we need to run conda activate to use all the packages inside Anaconda like the latest python (other than the system default one), jupyter-notebook, and so on.

(Reference: How to remove (base) from terminal prompt after updating conda.)