Search code examples
pythonjupyter-notebookgitlabgitlab-cigitlab-ci-runner

Gitlab-ci does not recognize python


I want to run my Jupyter notebooks with my pipeline. To do this i need runipy. And to install runipy on the gitlab runner i need python. But when i want to run the .gitlab-ci.yml script it gets stuck at printing the python version because python is not recognized.

.gitlab-ci.yml:

image: python:3.9

before_script:
  - python -V
  - pip install runipy

error:

Running with gitlab-runner 13.3.1 (738bbe5a)
  on JavaUnitTestRunner vr_SgzNd
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on DESKTOP-DJVC49J...
Getting source from Git repository
00:03
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/Gitlab-Runner/builds/vr_SgzNd/0/I438220/pharma/.git/
Checking out 65a225c0 as pipeline...
git-lfs/2.9.2 (GitHub; windows amd64; go 1.12.7; git 0274d856)
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ python -V
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
 the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\WINDOWS\TEMP\build_script377697220\script.ps1:195 char:1
+ python -V
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
ERROR: Job failed: exit status 1

When i try the same command in cmd everything works just fine.


Solution

  • Based on your log, you're using the shell executor. This will run commands on your local shell, just like you would yourself. The problem is the runner does not use your OS environment variables, so you need to add your python, git, etc. paths to the runner's path environment variable.

    The best way to do this is to configure the path variables explicitly in the environment variable in the [[runners]] section of your runner's config.toml. The config.toml file can either be in /etc/gitlab-runner/, ~/.gitlab-runner or / root. This StackOverflow thread shows how to do this. Please read Advanced Configurations for more info.

    If you want to download and use a custom docker image, like python:3.9, you need to use the Docker Executor.