Windows Server¶

If you are just testing your app on your personal computer, you can use otree runserver. You don’t need a full server setup as described below, which is necessary for sharing your app with an audience.

Note

There is now a Docker-based oTree installation, which may be easier than the below steps.

Create a virtualenv¶

It’s a best practice to use a virtualenv (though optional):

python3 -m venv venv_otree


You can configure PowerShell to always activate this virtualenv. Enter:

notepad \$shell


Then put this in the file:

cd "C:\path\to\oTree"
. "C:\path\to\oTree\venv_otree\Scripts\activate.ps1"


(Note the dot at the beginning of the line.)

Database (Postgres)¶

oTree’s default database is SQLite, which is fine for local development, but insufficient for production. We recommend PostgreSQL, although you can also use MySQL, MariaDB, or any other database supported by Django.

Install Postgres for Windows, using the default options. Note down the password you chose for the root postgres user.

When the installer finishes, open PowerShell and run psql -U postgres -W. (If the command is not found, make sure your PATH environment variable contains C:\Program Files\PostgreSQL\9.6\bin.)

Then enter these commands:

CREATE DATABASE django_db;
GRANT ALL PRIVILEGES ON DATABASE django_db TO otree_user;


Then exit the SQL prompt:

\q


Now you should tell oTree to use Postgres instead of SQLite. The default database configuration in settings.py is:

DATABASES = {
'default': dj_database_url.config(
default='sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')
)
}


However, instead of modifying the above line directly, it’s better to set the DATABASE_URL environment variable on your server. Setting the database through an environment variable allows you to continue to use SQLite on your development machine, while using Postgres on your production server.

If you used the values in the example above (username otree_user, password mypassword and database django_db), your DATABASE_URL would look like this:

postgres://otree_user:mypassword@localhost/django_db


To set the environment variable, do a Windows search (or control panel search) for “environment variables”. This will take you to the dialog with a name like “Edit system environment variables”. Add a new system entry for DATABASE_URL with the above URL.

Then restart PowerShell so the environment variable gets loaded.

Once DATABASE_URL is defined, oTree will use it instead of the default SQLite. (This is done via dj_database_url.)

psycopg2¶

To use Postgres, you need to install psycopg2 with pip3 install psycopg2. If the pip install doesn’t work, download it here. (If you are using a virtualenv, note the special installation instructions on that page.)

resetdb¶

If all the above steps went well, you should be able to run otree resetdb.

Install Redis¶

You should download and run Redis for Windows.

Redis should be running on port 6379. You can test with redis-cli ping, which should output PONG.

Next steps¶

The remaining steps are to deploy your code with Git as described here, and run the server as described here the steps are essentially the same as on Linux.

Then set up Sentry.