Skip to content
Snippets Groups Projects
VIPS Logo

VIPSCore-Python

Python implementation of VIPSCore, to enable models written in Python.

Notes to self

Consider using the advice listed here: https://github.com/zhanymkanov/fastapi-best-practices

Installation

Clone Gitlab repo

$ git clone git@gitlab.nibio.no:VIPS/VIPSCore-Python.git
$ cd VIPSCore-Python

Create and activate virtual environment

$ python3 -m venv venv
$ . venv/bin/activate 

Upgrade pip in virtual environment

(venv)$ python3 -m pip install --upgrade pip 
-> Successfully installed pip-22.3.1

Install dependencies from requirements.txt

(venv)$ pip install -r requirements.txt

Update dependencies

This was done at start of project, and must be repeated after all dependency changes:

TODO: Decide on whether to use pip freeze or manage requirements.txt manually. Ref e.g. this blogpost

(venv)$ pip install "fastapi[all]" (and others)

NB! fastapi[all] includes a lot of things, in order to get started quickly. Should consider importing only the relevant packages later on.

Start and stop virtual environment

$ . venv/bin/activate 
(venv)$ deactivate

Install VIPS models

The VIPS models available will vary between deployments of VIPSCore-Python. They are installed using pip, and specified in models.txt - which can be considered a deployment specific addendum to requirements.txt. Copy models_example.txt to models.txt to get started.

pip install -r models.txt

Development

Run application locally

(venv)$ uvicorn app.main:app --reload

Troubleshooting for Mac users

2023-02-14: When running the app locally on a Mac, this error occured when calling the /models endpoint:

unittest.case.SkipTest: No module named '_lzma'

Instructions to fix this are as follows :

$  brew install xz
$  pyenv uninstall 3.10.6
$  pyenv install 3.10.6