Install python 3.7 in machine executor

I’m trying to get a working version of python 3.7 to run in the machine executor.

I’ve tried the following, but am getting errors:

  • compile from source
    • can’t find the resulting .so python file
  • installation via pyenv
    • ssl library error
  • installation via the deadsnakes ppa
    • ssl library error

Here is a sample of my installation script, this currently fails due to the ‘_ssl’ library not being linked/installed properly.

version: 2
jobs:
  build:
    machine: true

    working_directory: ~/repo

    steps:
      - checkout
      - run:
          name: install ubuntu build reqs
          command: |
            sudo apt update && sudo apt upgrade -y
            sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
      - run:
          name: install python 3.7
          command: |
            sudo add-apt-repository --yes ppa:deadsnakes/ppa
            sudo apt-get update
            sudo apt-get install python3.7
            wget https://bootstrap.pypa.io/get-pip.py
            sudo python3.7 get-pip.py
            sudo python3.7 -m pip install --upgrade pip setuptools wheel
            sudo python3.7 -m pip install pipenv

Has anyone gotten python 3.7 installed and working in the machine executor?

What is the exact SSL error?

Hey,

So the first question is, do you really need the machine executor? This is simpler with Docker.

If you do need the machine executor, pyenv is already installed and Python v3.7.0 is pre-installed. You can try this:

version: 2
jobs:
  build:
    machine: true
    working_directory: ~/repo
    steps:
      - checkout
      - run:
          name: "Set Python Version"
          command: pyenv global 3.7.0
      - run:
          name: "Do things!"
          command: python run.py

Thanks!

It’s definitely debatable if I’m doing the appropriate configuration.

I started with a testing scheme locally using docker-compose. Where the service under-development is tested by bringing up only the supporting services, and running the key service tests with the key service communicating with the docker-compose raised supporting services.

As I understand, I can spin up the whole docker-compose full service using the docker executor. But with the way my project is structured I need to run tests outside and communicate with the docker-compose network.

Anyway, your suggestion, is more what I expected and was looking for. However, when I run the config below I get the error:

ERROR:

#!/bin/bash -eo pipefail pyenv global 3.7.0
pyenv: version `3.7.0' not installed

Config:

version: 2
jobs:
  build:
    machine: true
    working_directory: ~/repo
    steps:
      - checkout
  - run:
      name: install python 3.7
      command: |
        pyenv global 3.7.0
        sudo python -m pip install --upgrade pip setuptools wheel
        sudo python -m pip install pipenv

So as mentioned initially, I did try to install python 3.7.0 through pyenv, but the build process fails with the following error:

Updating /opt/circleci/.pyenv/plugins/pyenv-update...
From git://github.com/pyenv/pyenv-update
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Downloading Python-3.7.0.tar.xz...
-> https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
Installing Python-3.7.0...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems


BUILD FAILED (Ubuntu 14.04 using python-build 1.1.5-198-g835707da)

Inspect or clean up the working tree at /tmp/python-build.20181023003037.4964
Results logged to /tmp/python-build.20181023003037.4964.log

Last 10 log lines:
			install|*) ensurepip="" ;; \
		esac; \
		 ./python -E -m ensurepip \
			$ensurepip --root=/ ; \
	fi
Looking in links: /tmp/tmpucqugnjm
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
Exited with code 1

Config:
version: 2
jobs:
build:
machine: true

    working_directory: ~/repo

    steps:
      - checkout
      - run:
          name: update pyenv
          command: |
            # Install pyenv-update to allow addition of python 3.7.0
            git clone git://github.com/pyenv/pyenv-update.git $(pyenv root)/plugins/pyenv-update
            pyenv update
            pyenv install 3.7.0
      - run:
          name: Set Python Version
          command: pyenv global 3.7.0
      - run:
          name: install/update pip pipenv
          command: |
            sudo python -m pip install --upgrade pip setuptools wheel
            sudo python -m pip install pipenv

Hey,

So my apologies. What I provided before only worked because I was using a different VM. The best solution I can find is to use an updated machine image. The one in the example below already has Python 3.7.0:

version: 2
jobs:
  build:
    machine:
      image: circleci/classic:201808-01
    steps:
      - checkout
      - run:
          name: "Switch to Python v3.7"
          command: |
            pyenv versions
            pyenv global 3.7.0

You can see an example of this build running here.

1 Like

@FelicianoTech Thanks! With the image specification I was able to run python 3.7 with the machine executor! Just what I was looking for!

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.