Writing scripts for BrainVoyager in Python
- Details
- Category: Writing Scripts
- Last Updated: 23 February 2023
- Published: 27 March 2018
- Hits: 3905
Documentation
The documentation can be opened via the BrainVoyager menu > Python > Python Developer Guide. An unofficial list of functions can be found here: PDF. Example scripts can be found after installation of BrainVoyager in the directory /(My) Documents/BrainVoyager/PythonScripts/. A few extra scripts can be found on this support page.
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).