Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I got an error in my gitlab CI with Pip which is not found?

I'm trying to use gitlab CI for the first time. I just want to test (not to deploy) a Python program on it. I don't know why but it failed on pip, which is not found...

Here is the error message of gitlab :

Skipping Git submodules setup
$ pip install -r requirements.txt
/bin/bash: line 71: pip: command not found
ERROR: Job failed: exit code 1

And here my .gitlab-ci.yaml:

stages:
  - build
  - test

myJob:
  stage: build
  image: python:3.6
  script:
    - apt-get update -q -y
    - apt-get install -y python-pip
    - python -V
    - echo "hello world"
    - pip install -r requirements.txt

myJob2:
  stage: test
  script:
    - python test.py

Neither the hello world nor the Python version is printed. So I probably made a basic mistake, but which one?

like image 403
Slex Avatar asked Dec 26 '18 09:12

Slex


People also ask

How do you fix there was an error checking the latest version of pip?

Solve the Warning: There was an error checking the latest version of pip error. The best way to solve this error is to install or update the pip module to the latest version. Before installing the pip module make sure that all the dependencies for this module should be installed.

How do I get pip in Python?

Step 1: Download the get-pip.py (https://bootstrap.pypa.io/get-pip.py) file and store it in the same directory as python is installed. Step 2: Change the current path of the directory in the command line to the path of the directory where the above file exists. Step 4: Now wait through the installation process. Voila!


1 Answers

Different jobs in your pipeline are run in different containers. To be precise, they run in the container that you specify as image. The job myJob runs inside a python:3.6 container, so you have the pip command and everything works fine.

For your second job (myJob2), you did not specify any image, so the default image will be used, which will likely not be a python image.

Even if your second job was running inside a python container, it would still fail because of missing dependencies. You are installing the dependencies in the first job, but you did not specify any artifacts that should be passed to the next job. For more information on passing these artifacts check the Gitlab CI reference.

The following .gitlab-ci.yml should work:

stages:
  - build
  - test

myJob:
  stage: build
  image: python:3.6
  script:
    - apt-get update -q -y
    - apt-get install -y python-pip
    - python -V
    - echo "hello world"
    - pip install -r requirements.txt
  artifacts:
    untracked: true

myJob2:
  stage: test
  image: python:3.6
  script:
    - python test.py
like image 199
Tobias Geiselmann Avatar answered Oct 21 '22 02:10

Tobias Geiselmann