Home > BrainVoyager > Automation & Development > Writing Scripts > Writing Scripts for BrainVoyager in Python

Writing Scripts for BrainVoyager in Python

Documentation

The documentation can be opened via the BrainVoyager menu > Python > Python Developer Guide. An unofficial list of functions can be found in a PDF file attached to this page. Example scripts can be found after installation of BrainVoyager in the directory /(My) Documents/BrainVoyager/PythonScripts/. 

Screenshot 2021 12 07 at 17.10.27

A non-official, community-driven API reference can be found at http://fladd.github.io/BVPython/.

Tips for importing modules in a Python script for BrainVoyager

1. Make the path to the module available before importing. For example, if the module to import is located in /Documents/BrainVoyager/PythonScripts/, the command could be:

import os
import sys
scriptsdir = brainvoyager.choose_directory("Select the test scripts directory")
sys.path.append(scriptsdir)
import name_of_module

2. Avoid installing the package as egg in the site-packages directory of the conda environment for Python in BrainVoyager using the following installation command in the directory that contains setup.py:

pip install .

For example, download a *.zip file of bvbabel  Unzip the file. In the shell (Linux)/Terminal (macOS) /Conda prompt window (Windows), activate the Miniconda environment

conda activate env_bv_py38

then go into the bvbabel directory with the unzipped files via 'cd' (change directory). Type

$ pip install .

bvbabel should now be installed in opt/miniconda3/envs/env_bv_py38/lib/python3.8/site-packages/

From Stackoverflow

Notebooks

Please note that since BrainVoyager 22, Python code can be automatically generated in a BrainVoyager NoteBook (*.bvnb). This can be performed by clicking the icon "Log BV GUI Actions As Code" (see upper right corner in snapshot below).

AutoGenerationPythonCode BV22

1. Make the path to the module available before importing. For example, if the module to import is located in /Documents/BrainVoyager/PythonScripts/, the command could be:

import os
import sys
scriptsdir = brainvoyager.choose_directory("Select the test scripts directory")
sys.path.append(scriptsdir)
import name_of_module

2. Avoid installing the package as egg in the site-packages directory of the conda environment for Python in BrainVoyager using the following installation command in the directory that contains setup.py:

pip install .

For example, download a *.zip file of bvbabel  Unzip the file. In the shell (Linux)/Terminal (macOS) /Conda prompt window (Windows), activate the Miniconda environment

conda activate env_bv_py38

then go into the bvbabel directory with the unzipped files via 'cd' (change directory). Type

$ pip install .

bvbabel should now be installed in opt/miniconda3/envs/env_bv_py38/lib/python3.8/site-packages/

From Stackoverflow