简体   繁体   中英

Not able to upgrade python version to 3.7 using docker image in GitLab CICD

I am trying to use docker image in GitLab CICD pipeline above Python 3.5 version(as it is not supported any more and deprecated from Jan 2021), ie trying to upgrade to Python 3.7 using docker image. But while I am using in gitlab-ci.yml, I am not able to upgrade python and pip. It shows still the previous pip version. Please need your support.

There is a gitlab stage I am using by name of 'pytest':

pytest:
  stage: pytest
  image: python:3.7
  script:
    - python --version
    - python3 --version
    - pip3 --version
    - pip3 install --upgrade pip
    - which aws || pip3 install awscli
    - which eb || pip3 install awsebcli
    - python3 --version
    - pip3 --version

GitLab pipeline log as follows:

$ python --version
Python 2.7.12
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 20.3.4 from /var/opt/gitlab-runner/.local/lib/python3.5/site-packages/pip (python 3.5)
$ pip3 install --upgrade pip
DEPRECATION: Python 3.5 reached the end of its life on September 13th, 2020. Please upgrade your Python as Python 3.5 is no longer maintained. pip 21.0 will drop support for Python 3.5 in January 2021. pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /var/opt/gitlab-runner/.local/lib/python3.5/site-packages (20.3.4)
Collecting pip
  Using cached pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
  Using cached pip-20.3.3-py2.py3-none-any.whl (1.5 MB)
$ which aws || pip3 install awscli
/usr/local/bin/aws
$ which eb || pip3 install awsebcli
/var/opt/gitlab-runner/.local/bin/eb
$ python3 --version
Python 3.5.2
$ pip3 --version
pip 20.3.4 from /var/opt/gitlab-runner/.local/lib/python3.5/site-packages/pip (python 3.5)

Here we can see still the python version is 3.5.2 but I am trying to use python 3.7 from docker image. Need your valuable input. How can I upgrade docker image python to 3.7 and PIP accordingly in GitLab CICD?

Thanks in advance.

As requested by Kristian while tried with: apt-get update -yqq its throwing an error regarding access and I do not have permission to change the access as well.

$ apt-get update -yqq
W: chmod 0700 of directory /var/lib/apt/lists/partial failed - SetupAPTPartialDirectory (1: Operation not permitted)
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
Cleaning up file based variables
00:01
ERROR: Job failed: exit status 1

If I try your snipped I get the correct python and pip version:

stages:
  - pytest

pytest:
  image: python:3.7
  stage: pytest
  script:
    - python --version
    - python3 --version
    - pip3 --version

Output:

$ python --version
Python 3.7.10
$ python3 --version
Python 3.7.10
$ pip3 --version
pip 21.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

It seems your image is somehow messed up as python:3.7 should download the 3.7.10-buster Image.

What happens if you change the image to the tag image: python:3.7.10-buster ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM