Installation and Configuration of your Environment#

spot

This section presents how to configure your environment on your machine if you will use it during this course. This covers:

  • How to configure your Git environment to interact with the central Git server

  • How to configure the execution environment for applications developed during this course

  • How to install PyCharm development environment (IDE)

Note: it is very important that you follow exactly the steps described in this page, even if you have some of the described tools already installed on your computer.


Git Configuration#

Git installation#

If it is not installed yet, download Git for your platform and follow the instructions to install it (basically just running the installer).

On Windows, you need to install the MinGW environment that will provide a Unix Bash shell and a SSH client. MinGW is bundled as one of the components of Git for Windows: select it when prompted by the Git for Windows installer.

Note: on Windows, all the commands mentioned in this page must be executed in a Git Bash shell. First start it using the Start menu.

Repository access (SSH Keys)#

The work done during this course will be stored and versioned in Git on a central server, gitlab.lal.in2p3.fr. Authentication on this server is done using SSH keys. Ask in order to receive your personal SSH key in an email sent to your NPAC email address.

The workflow that will be used during the course requires that you install this SSH key on your machine. Depending on the OS running on your machine, the location of the SSH key is different:

  • Linux or MacOS: save the file sent to you by email in ~/.ssh. If the directory doesn’t exist, create it with:

    mkdir ~/.ssh
    
  • Windows machine: save the file sent to you by email in C:\Users\username\.ssh (replace username with your username). If the directory doesn’t exist, create it with:

    mkdir ${HOME}/.ssh
    

Except if you already have a SSH key that you use for something (see below), the file should be named id_rsa.

Once the file has been saved, you need to restrict the access to you only with the following command (On Windows, use the Bash shell provided by Git):

chmod 400 ~/.ssh/id_rsa

If you already have a file id_rsa in ~/.ssh on your personnal machine that you use for another purpose, you have the choice between 2 solutions:

  • The easiest, if you don’t need the other key during the course: temporarily rename your existing file and save the SSH key sent for the course with the standard name.

  • Save the SSH key sent to you with another name (don’t forget the chmod described above) and each time you start a new shell, execute the following commands:

    eval `ssh-agent`
    ssh-add ~/.ssh/your_key_name
    

Testing your Git setup#

If your Git and SSH configurations are correct, the following command should return no error:

ssh -T git@gitlab.lal.in2p3.fr

Execution Environment#

The course instructions assume that you are using the last version of Python distribution called Anaconda. It brings a consistent version of Python and many packages we depend on.

Note: if you already have Anaconda installed and you are not an Anaconda expert, we strongly advise you to reinstall Anaconda in a different location (during the installation, specify an installation path different from the current one) rather than trying to update your current version.

To install Anaconda, go to Anaconda Installation page and follow the instructions (select the 64-bit version for your platform). Accept the license and all the default answers. In particular, be sure to answer yes to the question about running conda init. At the end of the installation, ensure that Anaconda is activated with the following command (and restart your shell if advised to do it):

conda init --all

Note: if you get an error like conda: command not found when executing the command above, specify the full path to conda by prefixing the command with the installation path you specified during installation followed by the bin directory on Linux and MacOS or the Scripts directory on Windows.

Once the Anaconda installation is complete, check that the python binary launched by default is the one installed with Anaconda. The following command should show the path you selected as installation as the python binary path.

which python

In addition to the Anaconda base, the tools used during the exercises require two additional modules. The first one is pygit2, that needs to be installed with the following command (answer Y to all commands):

conda install -c conda-forge pygit2

Note: the phase solving the environment can take a while and is typically done twice, be patient!

The second is the package npac that contains necessary functionalities to start the exercises:

pip install npac --index-url https://gitlab.in2p3.fr/api/v4/projects/20121/packages/pypi/simple

PyCharm IDE#

PyCharm is one IDE (Integrated Development Environment) well suited for Python development and that we chose for this course. Even though you can use another development environment or editor you are used too, we strongly recommend that you install PyCharm. To do it, go to the PyCharm Installation page and follow the instructions to install the Community Edition.

PyCharm Configuration#

Note: the instructions below are based on PyCharm 2020.3. If you are using another version, some of the preference names or locations may be different. In this case, we advise you to update PyCharm, using the Help -> Check for updates menu: it should be straightforward and will reduce the risk of problems in the Anaconda support.

Before configuring PyCharm, display the Anaconda installation path (directory associated with base) with:

conda env list

Then start PyCharm to configure it:

  1. When you reach the “Welcome to PyCharm” screen, click on Customize in the left sidebar.

  2. Click on All settings… item at the bottom of the window.

  3. Choose Python Interpreter in the left sidebar.

  4. Click on the gear icon near the top-right corner and select Add… to add a new environment.

  5. Choose System Interpreter in the left sidebar.

  6. Click the ... button on the right of Interpreter and in the file dialog enter the Anaconda installation path retrieved previously. Open the corresponding folder and on Linux and MacOS the bin folder, then select the python file (on Windows, the file is named python.exe and is located directly into the installation folder).

If you are runing PyCharm on Windows, you may want to configure the PyCharm Terminal to use the Git Bash shell rather than the Windows Cmd Shell. To do this:

  1. Go to the global settings as previously.

  2. Click on Tools in the left sidebar, then on Terminal.

  3. In the Shell path field enter C:\Program Files\Git\bin\bash.exe.

  4. In the Tab name field enter Bash.

You can have a look to the corresponding screenshots

Report a Successful Installation#

Once you have completed all the steps described above, you may report your successful installation. For this, execute the following actions:

  • Create a file /tmp/test_installation.sh with the following contents:

     1#!/bin/bash
     2
     3echo "OS: $(uname)"
     4echo "Git server connection test output:"
     5echo "*********************************"
     6ssh -T git@gitlab.lal.in2p3.fr
     7echo "*********************************"
     8echo "Python path: $(which python)"
     9echo "Python version: $(python --version)"
    10echo "Git version: $(git --version)"
    11echo "Conda environment:"
    12echo "*****************"
    13conda list -f anaconda
    14echo ""
    15conda list -f astropy
    16echo ""
    17conda list -f pygit2
    18echo ""
    19conda env list
    20echo "*****************"
    

The critical configuration information to check is:

  • Anaconda version must be 2022.10