python - Couldn't import django in docker image on GitLab CI -
i tried running django tests python manage.py test in gitlab ci. therefore i'm using docker image. docker image builds fine, when runs tests on gitlab importerror: no module named 'django' and
couldn't import django. sure it's installed , available on pythonpath environment variable? did forget activate virtual environment? see .gitlab-ci.yml
image: registry.gitlab.com/app/core:latest services: - postgres:latest stages: - test variables: secret_key: test-secret postgres_db: ... postgres_user: ... postgres_password: ... python_tests: stage: test before_script: - export database_name=... - export database_user=... - export database_password=... - export database_host=postgres - source /app/venv/bin/activate script: - python manage.py test and dockerfile
from ubuntu:16.04 run apt-get update -y -qq run apt-get install -y -qq build-essential libffi-dev libpq-dev libfontconfig1 run apt-get install -y -qq python3 python3-dev python3-pip run apt-get install -y -qq libpq-dev run apt-get install -y -qq nodejs npm workdir /app # pip copy requirements.txt /app run pip3 install --upgrade pip run pip3 install virtualenv run virtualenv --no-site-packages venv run . venv/bin/activate run pip3 install -r /app/requirements.txt # npm run ln -s `which nodejs` /usr/bin/node copy web/vueapp/package.json /app run npm install
well have issue in approach. consider below run statements in dockerfile
run . venv/bin/activate run pip3 install -r /app/requirements.txt both above statements open 2 terminals, in 1 execute . venv/bin/activate , in 1 pip3 install -r /app/requirements.txt
so environment gets activated , let close , next pip3 statement installs on global packages. change code below
run . venv/bin/activate && pip3 install -r /app/requirements.txt when script running activate environment , running python manager.py inside virtual environment blank no packages. above change should fix issue you
Comments
Post a Comment