Skip to content

Installing Python

At your own computer

The instructions to install vary a bit based on which operating system you are using, but they are all essentially the same.

Install Python

On Mac or Linux, you probably already have python installed. On Windows, however it is a bit more complex.

Installing Python in Windows

You might have Python already installed, but we recommend that you install python via pyenv-win, for you to be able to use virtual environments with different Python versions.

Setting up pyenv-win

We will copy some of the install instructions from the pyenv-win how to install GitHub page here below, but we refer to the offical install instructions should there be problems.

NOTE: If you are running Windows 10 1905 or newer, you might need to disable the built-in Python launcher via Start > "Manage App Execution Aliases" and turning off the "App Installer" aliases for Python

Installing via PowerShell

The easiest way to install pyenv-win is to run the following installation command in a PowerShell terminal:

Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"

If you are getting any UnauthorizedAccess error as below then start Windows PowerShell with the "Run as administrator" option and run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine, and then re-run the above installation command. Note that changing the execution policy could potentially lower the security of your system. If you want to check your current execution policy level, before changing to RemoteSigned run Get-ExecutionPolicy in the PowerShell window.

For more information on 'digitally signed' or 'Security warning' you can refer to following issue #332

Installation of pyenv is now complete! The next step is to set up Python.

Setup Python

First, update the list of avaiable python version:

pyenv update

Then list the available python versions:

pyenv install --list

Then, install a version of python (e.g. 3.12.1):

pyenv install 3.12.1

Then, set the python version as your current python version:

pyenv global 3.12.1
pyenv local 3.12.1

Optionally (recommended), set up a virtual environment by installing and then creating a pipenv environment:

pip install pipenv
pipenv shell

Finally, upgrade/install essential packages for working with python packages:

pip install --upgrade pip setuptools wheel

Installing a C-compiler

To compile the models to C-code for faster simulation, you need to have a valid C-compiler. Below we offer some quick steps of installing a valid compiler on Windows, Linux or MacOS.

Windows

The full official Windows instructions are available here, but in short you want to first install/update setuptools, pip, 'wheel' if you haven't done this already:

pip install --upgrade setuptools pip wheel

Then you can either install the full version of visual studio, or a smaller standalone compiler (Build Tools for Visual Studio 2019). We recommend using the standalone compiler.

Standalone compiler

Download the Build Tools for Visual Studio 2019 installer, and run it. Make sure to install the C++ build tools and ensure the latest versions of MSVCv142 - VS 2019 C++ x64/x86 build tools and Windows 10 SDK.

Alternatively, you can install the compiler via the powershell, using winget (which should be preinstalled on most up-to-date) Windows versions. Note that the installation will take a long time without much feedback, so have patience. Also note that you will get a popup asking for elevated permissions.

winget install Microsoft.VisualStudio.2022.Community --override "--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"
Full Visual Studio install (not tested)

Download the full version installer of Sisual Studio, make sure to install Python development, Python native development tools, and Windows SDK (which can be found under Native development).

If the installer doesn't detect your toolset version, Set $env:PlatformToolset before building.

Linux

You probably already have a compiler available, otherwise install e.g. gcc through your package manager.

MAC

To get a C-compiler, you need to install Xcode. Xcode is available in the Mac app store. After installation, start Xcode and agree to the license agreement.

It might also be possible to install gcc, e.g. by opening a terminal and typing gcc which should prompt a request for installing Command line developer tools.

Make sure that you have also installed setuptools, pip, and wheel:

pip install --upgrade setuptools pip wheel

Note: on some versions of mac, we need to run using pip3 instead of pip, or in the following way:

python3 -m pip install --upgrade setuptools pip wheel

Make sure you have pip (the Python package installer) installed: From the terminal (Unix-users) or command window (Windows-users) try running pip --version (Linux/Mac users may have to write pip3). If pip is not installed, follow instructions here to install it.

When you have ensured that pip is installed, check that setuptools are installed by running

pip show setuptools

If installed it should show information about the setuptools package, such as version number. If not installed you can install it using pip: pip install setuptools.

At a computer in a LiU computer hall

Linux

If you are at a LiU shared computer running Linux (such as in the SU halls, or when logged in via ThinLinc), you need to first load the python package. To check which versions of python is available, open a terminal and run:

module avail python

This should print a list of available Python versions you could load. You probably want to use the version marked with (recommended) Then, to load the Python package and make it available, write the following into the terminal:

module add python/anaconda3-2023.03 

Note that python/anaconda3-2023.03 might have to be changed if other versions are found using the module avail command.

You can test if python is available by opening a terminal by running:

python --version

Windows

Python should/might already be available at the computer. If not, you need to change computer or connect to another computer using e.g. ThinLinc, or running on Google Colab.

Google Colab

Google Colab is a service where you can run Python code on a remote server. This can be good to share examples and do some initial testing. However, you need to know that data/files are not being saved, and thus you need to save and download the data from somewhere else.

Python software tools

Python software tools aids in the development workflow of Python programming, providing essential features and functionalities to streamline coding, debugging, and project management tasks. Some of the most common such tools are listed below and we encourage that you pick one up, as it will enhance your coding experience and ability.

Visual Studio Code (VS Code)

Visual Studio Code is a free, open-source code editor developed by Microsoft. It's highly customizable and features a rich ecosystem of extensions that can enhance its functionality for various programming languages, including Python.

Key Features:

  • Intelligent Code Editing: VS Code provides features like syntax highlighting, IntelliSense (code completion), code refactoring, and debugging capabilities.
  • Extensions: Its vast extension marketplace allows users to customize their development environment with themes, language support, and additional tools.
  • Integrated Terminal: VS Code includes a built-in terminal that allows developers to run commands, install packages, and execute scripts without leaving the editor.
  • Version Control: It has built-in Git support, enabling version control operations directly within the editor.
  • Cross-Platform: Available on Windows, macOS, and Linux, making it accessible to developers across different platforms.

When debugging in Vscode you are promoted to create a launch.json file, which then is stored in the .vscode folder in your project root directory. To make debugging more flexible, it is recommended that you add the following command to the launch.json file ""cwd": "${fileDirname}". This command makes the debugger navigate to the directory of the file you debug, which is helpful to make all relative paths in your code to work.

Anaconda

Anaconda is a distribution of Python and R programming languages primarily used for data science, machine learning, and scientific computing. It includes various tools and libraries pre-installed, making it easier for users to set up a Python environment for data-related tasks.

Key Features:

  • Package Management: Anaconda comes with its own package manager called conda, which simplifies the process of installing, updating, and managing Python packages and dependencies.
  • Environment Management: Users can create isolated Python environments using conda, allowing them to manage different sets of packages and dependencies for different projects.
  • Pre-installed Libraries: Anaconda includes popular data science and machine learning libraries like NumPy, pandas, SciPy, scikit-learn, TensorFlow, and Jupyter.
  • Navigator: Anaconda Navigator provides a graphical interface for managing environments, installing packages, and launching applications such as Jupyter Notebook and Spyder.

Spyder

Spyder is an open-source integrated development environment (IDE) designed specifically for scientific computing and data analysis using Python. It provides a powerful environment for interactive computing and visualization.

Key Features:

  • Editor: Spyder features a code editor with syntax highlighting, code completion, and code analysis capabilities.
  • Variable Explorer: It includes a variable explorer that displays data objects, arrays, and variables in memory, allowing users to inspect and manipulate them interactively.
  • IPython Console: Spyder integrates an IPython console, providing an interactive environment for executing Python code, exploring data, and plotting graphs.
  • Debugger: The IDE offers debugging capabilities, allowing users to set breakpoints, inspect variables, and step through code execution.
  • Plotting: Spyder includes a built-in plotting functionality powered by Matplotlib, making it easy to visualize data and generate plots directly within the IDE.

Jupyter Notebook / JupyterLab

Jupyter Notebook and JupyterLab are web-based interactive computing environments widely used for data analysis, visualization, and collaboration. They support various programming languages, including Python, R, and Julia, and allow users to create and share documents containing live code, equations, visualizations, and narrative text.

PyCharm

PyCharm is a powerful Python IDE developed by JetBrains. It provides advanced features such as intelligent code completion, refactoring, version control integration, and support for web development with Django and Flask frameworks.

Sublime text

Sublime Text is a lightweight yet powerful code editor known for its speed and simplicity. It offers features like multiple selections, split editing, and a rich selection of plugins and themes.