getgauge / gauge-python

Python language runner for Gauge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File "check_and_install_getgauge.py", line 5, ImportError: No module named pkg_resources with Python 3.7

imranrazakhan opened this issue · comments

Describe the bug
I am preparing docker image with python3 and running my specs but its giving error

File "check_and_install_getgauge.py", line 5, in <module>
import pkg_resources
ImportError: No module named pkg_resources

To Reproduce
Run gauge run -e pre_prod specs/my --tags "\!WIP"

Logs

>> gauge run -e pre_prod specs/my --tags "\!WIP"
Traceback (most recent call last):
File "check_and_install_getgauge.py", line 5, in <module>
import pkg_resources
ImportError: No module named pkg_resources
Error occurred while waiting for runner process to finish.
Error : exit status 1
Error ----------------------------------

[Gauge]
Failed to start gauge API: Error occurred while waiting for runner process to finish.
Error : exit status 1

Get Support ----------------------------
        Docs:          https://docs.gauge.org
        Bugs:          https://github.com/getgauge/gauge/issues
        Chat:          https://github.com/getgauge/gauge/discussions

Your Environment Information -----------
        linux, 1.1.8, b1501f4
        flash (0.0.2), html-report (4.0.12), json-report (0.3.5), python (0.3.15), screenshot (0.0.1), spectacle (0.1.4), xml-report (0.2.3)

Versions:

  • OS [Docker image base on "node:15.6.0-buster"]
  • Python version
    Python 3.7.3
  • Gauge Version
Gauge version: 1.1.8
Commit Hash: b1501f4

Plugins
-------
flash (0.0.2)
html-report (4.0.12)
json-report (0.3.5)
python (0.3.15)
screenshot (0.0.1)
spectacle (0.1.4)
xml-report (0.2.3)

Additional context

apt update && apt install -y python3  python3-pip && \
    apt install --reinstall python3-pkg-resources python3-setuptools && \
    pip3 uninstall setuptools && \
    pip3 install --no-cache --upgrade wheel
gauge run -e pre_prod specs/my --tags "\!WIP"

This command tries to install gauge [python](pip install getgauge) package on the first run.

With Docker it's best to install this dependency while building the image for example.

apt update && apt install -y python3  python3-pip && \
    apt install --reinstall python3-pkg-resources python3-setuptools && \
    pip3 uninstall setuptools && \
    pip3 install --no-cache --upgrade wheel \
    pip3 install getgauge

Please note you can also install gauge executable via the getgauge-cli

@zabil Sorry i missed to update before running gauge I am installing getgauge from requirements.txt in dockerfile. Following is my dockerfile

FROM node:15.6.0-buster

ENV HEADLESS 1
ENV overwrite_reports true

ENV PYTHONUNBUFFERED=1

RUN apt update -y && apt upgrade -y python3
RUN apt install -y python3-pip && \
    apt install --reinstall python3-pkg-resources python3-setuptools
RUN python3 -m pip install --upgrade pip setuptools wheel

WORKDIR /home/testsuite

RUN apt update && apt install -y wget gnupg git ca-certificates unzip chromium chromium-driver

RUN npm install @getgauge/cli
RUN ln -s /home/testsuite/node_modules/.bin/gauge /usr/bin/gauge

RUN gauge install python && gauge install spectacle && gauge install xml-report && gauge install html-report \
    && gauge install screenshot && gauge install flash && gauge install json-report && gauge update -c \
    && gauge update -a && gauge telemetry off

# copies local folder
COPY gauge_tests /home/testsuite/gauge_tests
WORKDIR /home/testsuite/gauge_tests
RUN pip3 install --no-cache-dir -r requirements.txt

CMD tail -f /dev/null

You are probably seeing this because there are two versions of python installed on the image. By default Gauge refers to the executable python which in this image is.

python --version
Python 2.7.16

What you need to refer to is python3

You can change this by editing this line in python.properties as follows

root@1b14720c1654:/home/testsuite/gauge_tests# cat env/default/python.properties
GAUGE_PYTHON_COMMAND = python3

# Comma seperated list of dirs. path should be relative to project root.
STEP_IMPL_DIR = step_impl

Make sure you've rebuilt the image so that COPY gauge_tests /home/testsuite/gauge_tests copies the updated files.

@zabil Thanks this resolved issue, I have to also add one more package python3-tk , following is working docker file it may help others

FROM node:15.6.0-buster

ENV HEADLESS 1
ENV overwrite_reports true
ENV PYTHONUNBUFFERED=1

RUN apt update -y && apt upgrade -y && \
        apt install -y python3-pip python3-tk && \
        python3 -m pip install --upgrade --user pip

WORKDIR /home/testsuite

RUN apt update && apt install -y wget gnupg git ca-certificates unzip chromium chromium-driver

RUN npm install @getgauge/cli
RUN ln -s /home/testsuite/node_modules/.bin/gauge /usr/bin/gauge

RUN gauge install python && gauge install spectacle && gauge install xml-report && gauge install html-report \
    && gauge install screenshot && gauge install flash && gauge install json-report && gauge update -c \
    && gauge update -a && gauge telemetry off

# copies local folder
COPY gauge_tests /home/testsuite/gauge_tests
WORKDIR /home/testsuite/gauge_tests

RUN python3 -m pip install --no-cache-dir -r requirements.txt

CMD tail -f /dev/null

Please note, you can use

RUN pip install getgauge-cli

Instead of

RUN npm install @getgauge/cli
RUN ln -s /home/testsuite/node_modules/.bin/gauge /usr/bin/gauge

More info at https://pypi.org/project/getgauge-cli/

Please note, you can use

RUN pip install getgauge-cli

Instead of

RUN npm install @getgauge/cli
RUN ln -s /home/testsuite/node_modules/.bin/gauge /usr/bin/gauge

More info at https://pypi.org/project/getgauge-cli/

@zabil This suggestions results in following error

 => ERROR [ 7/11] RUN gauge install python && gauge install spectacle && gauge install xml-report && gauge install html-report     && gauge install screenshot && gauge install  0.5s
------
 > [ 7/11] RUN gauge install python && gauge install spectacle && gauge install xml-report && gauge install html-report     && gauge install screenshot && gauge install flash && gauge install json-report && gauge update -c     && gauge update -a && gauge telemetry off:
**#10 0.474 /bin/sh: 1: gauge: not found**

Please try

FROM node:15.6.0-buster

ENV HEADLESS 1
ENV overwrite_reports true

ENV PYTHONUNBUFFERED=1

RUN apt update -y && apt upgrade -y python3
RUN apt install -y python3-pip && \
    apt install --reinstall python3-pkg-resources python3-setuptools
RUN python3 -m pip install --upgrade pip setuptools wheel

WORKDIR /home/testsuite

RUN apt update && apt install -y wget gnupg git ca-certificates unzip chromium chromium-driver

RUN pip3 install getgauge-cli

RUN gauge install python && gauge install spectacle && gauge install xml-report && gauge install html-report \
    && gauge install screenshot && gauge install flash && gauge install json-report && gauge update -c \
    && gauge update -a && gauge telemetry off

# copies local folder
COPY gauge_tests /home/testsuite/gauge_tests
WORKDIR /home/testsuite/gauge_tests
RUN pip3 install --no-cache-dir -r requirements.txt

CMD tail -f /dev/null

This works for me

@zabil Previously i used following line

RUN python3 -m pip install --upgrade pip setuptools wheel getgauge-cli

But below changes works

RUN python3 -m pip install --upgrade pip setuptools wheel
RUN python3 -m pip install getgauge-cli