Setting up Python Scripting

Setting up Python Scripting

In SAMSON, Python scripting relies on Python 3.9, which you need to install separately.

Windows

On Windows, we recommend using Anaconda to install Python and all required dependencies.

Download and execute Anaconda3 v.2021.11. Installation should be straightforward, but you can find more information here.

During the installation, make sure to check the option to add Anaconda3 to your PATH environment variables such that it could be found by SAMSON, see the image below:

 

If you have not opted for this option during the installation then after installation, you will need to modify your PATH environment variable to make Python accessible.

If you have installed Anaconda for all users (in admin mode), add the following paths:

C:\Anaconda3
C:\Anaconda3\usr\bin
C:\Anaconda3\bin
C:\Anaconda3\Scripts

If you have installed Anaconda for yourself only, add the following paths instead:
C:\Users\YourUserName\Anaconda3
C:\Users\YourUserName\Anaconda3\Library\usr\bin
C:\Users\YourUserName\Anaconda3\Library\bin
C:\Users\YourUserName\Anaconda3\Scripts

where YourUserName should be replaced by your user name. Here is an example for user marin.

 

Linux

For Linux, we recommend installing Python via Anaconda.

Download and execute Anaconda3 v.2021.11. Installation should be straightforward, but you can find more information here.

During the installation, the installer prompts “Do you wish the installer to initialize Anaconda3 by running conda init?” We recommend choosing “yes” such that it will be added into your PATH environment variable in your ~/.bashrc file.

If you chose not to initialize conda during the installation, then after installation you will need to initialize Anaconda3 (see here) and modify your PATH environment variable to make Python accessible. To do this, append the following line into your ~/.bashrc file:
export PATH=/home/YourUserName/anaconda3/bin:$PATH

where YourUserName should be replaced by your user name.

 

Mac OS

On Mac OS, you will need Python v.3.9 and Jupyter QtConsole v.5.1.

Python can be installed via Homebrew or from python.org. Below, we describe the installation procedure via Homebrew.

Warning: The Python Scripting Extension might not work with the Anaconda installation on Mac OS due to a possible clash between the versions of Qt Framework used by SAMSON and the Qt library used by the Jupyter QtConsole provided by Anaconda.

To install Homebrew, please, follow the instructions on the Homebrew website. Please read first the Homebrew Installation Documentation, especially the macOS requirements section.

If you have a single user or would like to install homebrew for all users, then you only have to run the following command:
– for x86_64 architecture:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

– for Apple M1 architecture specify to use homebrew for x86_64 architecture:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you would like to install homebrew only for your user, please check out the Installation of homebrew in a local directory section below.

If you would like, you can update homebrew:
brew update

Now, to install Python 3.9 run the next command:
brew install python@3.9

After that, you may be asked to link the executable:
brew link python@3.9

To verify the version of Python run:
python3 --version

The pip3 package manager should be automatically installed with Python 3 by Homebrew.
Optionally, you may want to update pip3:
pip3 install --upgrade pip setuptools wheel

To be able to use Python Scripting in SAMSON, it’s necessary to install the following packages in the specified order:
pip3 install sip PyQt5==5.12.3 jupyter qtconsole

[Optional] If you would like to use the matplotlib package, you may first need to install pkg-config, libpng and freetype if they aren’t installed already.
brew install pkg-config libpng freetype
pip3 install matplotlib

Mac OS: Installation of homebrew in a local directory

If you don’t have root privileges, you might follow the multiple installations instructions to install homebrew in your user’s directory. For example, to install it in the ~/homebrew directory execute the following commands in the terminal:
cd $HOME
mkdir homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

As suggested in the install script, add Homebrew to your PATH.
If you installed Homebrew for all users in a non-default folder (e.g., in /opt/ ), then execute in the terminal (please modify the path to homebrew if necessary):
echo 'PATH=/opt/homebrew/bin/:$PATH' >> $HOME/.zprofile
If you installed Homebrew only for your user (e.g., in ~/homebrew), then execute in the terminal (please modify the path to homebrew if necessary):
echo 'PATH=$HOME/homebrew/bin/:$PATH' >> $HOME/.zprofile
Then restart your terminal – simply close and open it again.

If  you have a mac with the Apple M1 architecture, please run:

arch -x86_64 brew update

arch -x86_64 brew install python@3.9

to use the x86_64 architecture.

Proceed with the next steps in the installation on mac OS section.

Please note that in the case of the installation of homebrew in a local or non-default folder, SAMSON might not be able to find the proper python and you might need to launch SAMSON from the terminal as follows:
cd $HOME/Applications
open SAMSON.app

Verifying your installation

To test the installation, you can try to open the Jupyter Qt Console by executing the next command in the terminal (for Windows: Anaconda terminal):
jupyter qtconsole

Now, you should be able to use Python Scripting in SAMSON. Launch SAMSON, and go to the Interface menu to start Python Scripting. You can also use the Apps menu (Apps > General > Python Scripting).

The Python Scripting console should appear after a few seconds of its initialization:

 

If neither option seems available, please verify that you properly specified the environment variables as described above.

Contact us if you experience any problems.

Comments are closed.