Starting with Python
Python, Anaconda, Conda,virtual environment, Spyder, experimental psychology, tutorial, installation, DevStart, developmental science
Python is one of the most popular programming languages in general. In data science, it competes with Matlab and R for first place on the podium.
In our everyday we often use python to pre-process and analyze the data. In this tutorial we will explain our preferred way of installing python and managing its libraries. There are several ways to install python, this is the one we recommend for its simplicity and flexibility.
We strongly recommend using our interactive flowchart to guide yourself through the tutorials! It will help you follow the setup steps in the right order based on your experience level.
Flowchart
Installing Python
Miniconda
Miniconda is our favorite way to install Python, and for good reason! While you’ve probably heard of Anaconda – that feature-packed GUI many folks use to manage Python, packages, and environments – Miniconda is its sleek, lightweight counterpart.
What makes Miniconda special? It skips all the extra GUI elements and pre-installed packages that come with Anaconda. The result? A much lighter installation that doesn’t weigh down your system! With Miniconda, you get just the essentials: Conda, Python, and a few critical dependencies. This minimal setup gives you greater control over what gets installed, keeping everything lean and efficient. Plus, it includes the default Conda package manager and channels, so you still have full access to the official Conda repository for all your package needs.
To use Miniconda download the installer from Miniconda (remember to scroll down under Anaconda)
The installation process is similar to that of Anaconda. Once the installation is complete, you will find the Anaconda Prompt among your programs. This prompt serves as your interface for installing Python packages and creating environments. To verify everything’s working properly, simply type conda
. You’ll be greeted with a comprehensive list of available conda commands ready for you to explore and use (we will see below how to do so).
To use Miniconda download the installer from Miniconda (remember to scroll down under Anaconda)
⚠️ Important
Please make sure that you select the correct version for your system!!! Select the version depending if you have Apple Silicon or an Intel processor.
Once the installation is complete, you’ll have the full power of Miniconda at your fingertips through your terminal! To verify everything’s working properly, simply open your terminal and type conda
. You’ll be greeted with a comprehensive list of available conda commands ready for you to explore and use (we will see below how to do so).
Managing environments
Python has different versions, and so do all the packages you install (like PsychoPy, numpy, pandas, etc.). Here’s the problem: different projects often need different versions of the same tools.Project A might need Python 3.9 with PsychoPy version 2022.1, while Project B might need Python 3.11 with PsychoPy version 2023.2, and your system analysis scripts might work best with the latest versions of everything.
Virtual environments create separate “sandboxes” for each project. Each sandbox has its own Python version and package versions, completely isolated from the others. You can switch between these environments easily, ensuring each project gets exactly what it needs without conflicts.
Without virtual environments, installing new packages can break your existing projects. It’s like trying to run Windows 95 software on Windows 11 – things get messy fast.
One of the best features of Miniconda is how easily you can create and manage environments. Conda lets you create, export, list, remove, and update environments with different Python versions and packages. Let’s create an environment called working
that we’ll use for our everyday tasks and let’s make sure to have python in it.
To do this, open the Anaconda Prompt and type:
conda create --name working python
Press y
when asked and after few seconds we will have out new working
environment. Now we want to tell our Anaconda prompt that we want to work on our brand new working
environment. To do so let’s write:
conda activate working
To do this, open your terminal and type:
conda create --name working python
Press y
when asked and after few seconds we will have out new working
environment. Now we want to tell our Anaconda prompt that we want to work on our brand new working
environment. To do so let’s write:
conda activate working
You’ll notice that the name on the left side of the command prompt has changed from base
to working
. This indicates that everything you do in the Anaconda Prompt now will apply to the working
environment.
Now we would probably want to install some packages in this new environment. Follow the tutorials
When you install Anaconda or Miniconda, you get a default environment called base
. This contains the essential tools that make conda work properly. It is recommended to avoid installing packages in the base environment - always create new environments for your work.
Installing python packages
To pre-process and analyze the data we will need some specific packages. It is easy to install and manage packages using conda.
We will use the command conda install …
and a list of packages. Here we will install pandas (a package to handle dataframes), numpy (library to manage arrays), matplotlib and seaborn (two libraries to plot data), spyder-kernels (to allow interaction with the Spyder GUI that we will cover later on).
To do so:
Open the Anaconda prompt and type :
conda install pandas numpy matplotlib seaborn spyder-kernels
After thinking about for few seconds the prompt will download the package and its dependencies.
Occasionally, conda may encounter difficulties locating the precise package you need. In such cases, pip, another renowned Python package manager, can come to the rescue. You might already be aware of pip
, versatility for installing and manage packages in Python.
Let’s consider I2MC, an exceptional package processing eye-tracking data. With pip, installation is a breeze. Simply use the following command:
pip install I2MC
Open your terminal and type :
conda install pandas numpy matplotlib seaborn spyder-kernels
After thinking about for few seconds the prompt will download the package and its dependencies.
Occasionally, conda may encounter difficulties locating the precise package you need. In such cases, pip, another renowned Python package manager, can come to the rescue. You might already be aware of pip
, versatility for installing and manage packages in Python.
Let’s consider I2MC, an exceptional package processing eye-tracking data. With pip, installation is a breeze. Simply use the following command:
pip install I2MC
We may use additional packages in specific tutorials, but don’t worry – we’ll always mention which ones you need and provide clear installation instructions when the time comes!
Installing Spyder IDE
Now that we have our environment and packages set up, how do we actually use them? Sure, we could type Python commands directly in the terminal… but let’s be honest, that would be tedious and inefficient for any serious work!
What we need is an IDE – and our choice is Spyder! Spyder is a powerful scientific IDE built specifically for scientists, engineers, and data analysts. With features like variable exploration, integrated plotting, and excellent debugging tools, it’s perfect for writing and running Python code efficiently.
Installing Spyder is straightforward. To get started, visit the Spyder website, download the appropriate installer for your operating system, and install it on your machine.
Once installed, you can launch Spyder. Here it is in all its glory:
Here’s the key part: you can configure Spyder to use any environment you’ve created. Simply click Console, select New Console in Environment, and choose your desired environment (for example the working one). This means that the code you will now run into Spyder will access the python and the packages you have in the specific environment.
That’s it—now any code you run will execute within the environment you selected. Well done!
To properly run Spyder while connected to your environments, your environment needs to include a specific library.
Thus you need to install it by:
conda install spyder-kernels
or
pip install spyder-kernels
we should have already instaleld this but in case you didn’t please do install it.