diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index adbaf21dc985ddc5c0cdcba0608845ba111e550a..7d2e69e933b7ca104b4159b3ffeecd1e60069482 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,11 +23,12 @@ build_cmake:
 build_python:
   stage: build
   before_script:
-    - apt update && apt -y install git gcc cmake mpich python3 python3-pip
-    - python3 -m pip install numpy
+    - apt update && apt -y install git gcc cmake mpich python3 python3-pip python3-venv
+    - python3 -m venv ./venv
+    - ./venv/bin/python -m pip install numpy wheel
   script:
-    - python3 setup.py bdist_wheel
-    - python3 -m pip install dist/*
+    - ./venv/bin/python setup.py bdist_wheel
+    - ./venv/bin/python -m pip install dist/*
   artifacts:
     paths:
       - dist/*.whl
@@ -43,12 +44,13 @@ build_docs:
   dependencies:
     - build_python
   before_script:
-    - apt update && apt -y install mpich python3 python3-pip
-    - python3 -m pip install --upgrade pip
-    - python3 -m pip install numpy
-    - python3 -m pip install dist/*
-    - python3 -m pip install Sphinx sphinx-rtd-theme sphinxcontrib-napoleon numpydoc myst-parser
+    - apt update && apt -y install mpich python3 python3-pip python3-venv
+    - python3 -m venv ./venv
+    - ./venv/bin/python -m pip install numpy wheel
+    - ./venv/bin/python -m pip install dist/*
+    - ./venv/bin/python -m pip install Sphinx sphinx-rtd-theme sphinxcontrib-napoleon numpydoc myst-parser
   script:
+    - source ./venv/bin/activate
     - cd docs
     - make dirhtml
   artifacts: