To open a project in PyCharm (e.g. a demo), click ‘Open’ in the PyCharm welcome screen, then navigate to the directory containing the project, select the project, and click ‘Open’. Alternatively, if you already have a PyCharm project open, click ‘File’ > ‘Open’, find the directory, select it, and click ‘Open’.

When you open a new project in PyCharm, you should see a dialogue box that says something like “File requirements.txt contains project dependencies. Would you like to create a virtual environment using it?”. In the dependencies field you should see a path ending in requirements.txt. Replace “requirements.txt” with “constraints.txt” and then click “OK”. PyCharm will then create a virtual environment for you and install all the required packages.

Note

This workflow uses virtualenv to create an isolated virtual environment for each project. PyCharm remembers which virtual environment to use for each project, and will load it automatically when you open the project.

Note

If you are not using PyCharm, you can install the required packages using the following command:

pip install -r constraints.txt

Note

Why do we install from constraints.txt rather than requirements.txt? requirements.txt is written manually by the experimenter, and lists all the packages that they want to use in their experiment. constraints.txt is then automatically generated by PsyNet, and additionally lists all the dependencies of the packages in requirements.txt. Importantly, PsyNet ensures that the versions of the packages in constraints.txt are compatible with the current version of PsyNet. Moreover, listing these versions explicitly in constraints.txt means that when future experimenters come to run the experiment, they will be able to install exactly the same versions of the packages that we originally used.

If you do not see this PyCharm dialogue box, you can instead create the virtual environment by clicking the interpreter box in the bottom right corner of the screen (it might say something like ‘No interpreter selected’ or ‘Python 3.X’), then clicking ‘Add new interpreter’ > ‘Add local interpreter’. Select ‘Virtualenv environment’, select ‘New’, make sure that the correct version of Python is selected, then press OK. PyCharm will spend some time processing this selection, but then when you open a new terminal tab it should load your virtual environment automatically.

If you are working as a PsyNet developer, now is the moment to install PsyNet and Dallinger in development mode. To do this, run the following commands (assuming you have installed PsyNet and Dallinger in the default locations):

pip install -e ~/PsyNet
pip install -e ~/Dallinger

Whenever you develop or deploy an experiment using PsyNet (assuming you are not using Docker) you will need to make sure you are in the appropriate virtual environment. You can confirm that you are in the correct virtual environment by looking at the start of your terminal prompt. It should look something like this: (my-project) your-name@your-computer-name ~ %. If you have only just created your new virtual environment in PyCharm, you might need to open a new terminal window for your virtual environment to be loaded. Your virtual environment should activate automatically when you open your project in PyCharm; if it does not, you can select it by clicking the interpreter box in the bottom right corner of the screen.

Once PyCharm has finished installing the required packages, you should be able to run the experiment with the following command:

psynet debug local

Note

If you are not using PyCharm, you can create a virtual environment using the following command:

mkvirtualenv my-project --python $(which python3)

where in this case my-project is the name of the virtual environment.

You can activate your virtual environment by running the following command:

workon my-project

You can then delete your virtual environment by running the following command:

rmvirtualenv my-project

Note

If you experience problems setting up the virtual environment:

  • Check in which directory virtualenvwrapper.sh is installed. This might be a different directory than ‘~/.local/bin/’. In that case, adapt the code above to source this file accordingly.

  • Check whether the directory where virtualenvwrapper.sh was installed is added to PATH. If not, add the directory to PATH.