Windows - Manually Creating a Virtual Environment

Overview

This guide will walk you through the steps of creating a virtual environment manually for LibreOffice in Windows.

While Pre-configured virtual environments for Windows are available, this guide is for those who want to create their own virtual environment.

Another option is to use the Include Python Path for LibreOffice extension to add virtual environment paths to LibreOffice, this would work with all LibreOffice versions after Version 7.0 on all operating systems.

For the purpose of this guide we will assume your project directory is D:\tmp\manual

Note

This guide is for use with pip only. See Also Windows - Creating a Poetry Virtual Environment for LibreOffice for more information.

Steps

Get Version of LibreOffice Python

Get the version that the current installed LibreOffice is using.

&"C:\Program Files\LibreOffice\program\python.exe" --version

This will output something like: 3.8.16. We will need this value later.

Create Virtual Environment

Create the virtual environment. It is important the --without-pip be included.

cd D:\tmp\manual\
python -m venv --without-pip .venv

Now there will be a subdirectory D:\tmp\manual\.venv.

Edit .venv\pyvenv.cfg, use version found above 3.8.16. So, if your found version is 3.10.5 then the version_info would read version_info = 3.10.5.final.0 and so on. The prompt line is completely optional and can be what you want.

home = C:\Program Files\LibreOffice\program
implementation = CPython
version_info = 3.8.16.final.0
virtualenv = 20.17.1
include-system-site-packages = false
base-prefix = C:\Program Files\LibreOffice\program\python-core-3.8.16
base-exec-prefix = C:\Program Files\LibreOffice\program\python-core-3.8.16
base-executable = C:\Program Files\LibreOffice\program\python.exe
prompt = myproject_3.8.16

Note

If include-system-site-packages = true then both C:\Users\guide\AppData\Roaming\Python\Python38\site-packages (if it exist) and C:\Program Files\LibreOffice\program\python-core-3.8.16 will also be included on python’s sys.path. This is usually not needed.

Activate Virtual Environment

.\.venv\Scripts\Activate.ps1

Install Pip

Install pip (virtual environment must be active)

Invoke-WebRequest -Uri https://bootstrap.pypa.io/get-pip.py -UseBasicParsing).Content | python.exe -

Test by checking version:

(myproject_3.8.16) PS D:\tmp\manual> python -m pip --version
pip 23.1.2 from D:\tmp\manual\.venv\lib\site-packages\pip (python 3.8)

Install extra python packages.

python -m pip install ooo-dev-tools

A test to see if it worked, see Test installed package.

Note

Note that it is import that pip be run with python -m pip to ensure the correct pip is being used.