Skip to content

Instantly share code, notes, and snippets.

@thekalinga
Last active January 28, 2022 01:54
Show Gist options
  • Save thekalinga/b74056272cb1afdabf529a332ff0f517 to your computer and use it in GitHub Desktop.
Save thekalinga/b74056272cb1afdabf529a332ff0f517 to your computer and use it in GitHub Desktop.
Setup python environment for writing macros with pyenv, virtualenv, visual studio code, libre office uno

Libre office python development environment setup guide

Setup

  1. Install Visual studio code
  2. Install Python plugin for visual studio
  3. Install pyenv that helps you manage multiple versions of python side by side
  4. Install pyenv-virtualenv helps you utilize python virtualenvs inside pyenv

git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

  1. Libre Office only provides python3 system packages, not pip packages.

sudo apt-get install libreoffice python3 libreoffice-script-provider-python uno-libs3 python3-uno

These will install python3 & all other packages required by uno

  1. Since pyenv manages its own version of python, these system level packages needs to be shared with the pyenv's virtual environment

Create a virtual environment named uno inside pyenv

If python 3.4 is currently set as the global version in pyenv, you can run the following command.

pyenv virtualenv -p /usr/bin/python3.4 --system-site-packages uno

else run

pyenv virtualenv 3.4.3 -p /usr/bin/python3.4 --system-site-packages uno

This will create a new virtual environment within pyenv called uno

You can test that this is present by running pyenv virtualenvs

  1. Set uno as the default version

pyenv global uno

Now the setup is complete

Create project

Creating the project is as simple as virtualenv uno-playground

You should see your virtualenv project uno-playground created in the current directory.

Now, lets activate current virtual environment under uno-playground by running

source bin/activate

Since vscode(Visual studio code) python plugin uses pylint for linting & autopep8 for formating, lets install them inour virtualenv.

Also, libre office makes interacting with uno controller easier via unotools package

Lets install all three of them using

pylint autopep8 unotools

Now open the project in Visual studio code & start writing your extensions.

Additional Notes

Add the following to your ~/.zshenv (or) ~/.bash_profile to activate the virtual environments automatically

export PATH=$PATH:/usr/local/bin
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Resources

  1. Interface-oriented programming in OpenOffice / LibreOffice
  2. SCRIPTING LIBREOFFICE WITH PYTHON
  3. How to use (on Ubuntu 14.04) section here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment