CityOfZion / neo-python

Python Node and SDK for the NEO 2.x blockchain. For NEO 3.x go to our successor project neo-mamba
https://neo-python.readthedocs.io/en/latest/
MIT License
313 stars 189 forks source link

Issue with running pip inside docker #1011

Closed volekerb closed 4 years ago

volekerb commented 5 years ago

After bumping up python version to 3.7 in #1008 Command CMD pip3 install -e . triggers pip 3.6 version but not 3.7 and dependencies could be installed with an error:

Step 9/11 : RUN pip3 install -e .
 ---> Running in be35c386c2b8
Obtaining file:///neo-python
neo-python requires Python '>=3.7' but the running Python is 3.6.8
The command '/bin/sh -c pip3 install -e .' returned a non-zero code: 1
ixje commented 4 years ago

I'm not a docker expert, so I'll ask for some input from @nunojusto

What I found is

RUN - command triggers while we build the docker image.

CMD - command triggers while we launch the created docker image

From the above I worry that changing from RUN to CMD will affect the image building. What do you think @nunojusto ?

LysanderGG commented 4 years ago

Imo the problem is that ubuntu comes with python 3.6.8 by default and therefore python and pip3 still refer to the python-3.6 versions. You need to use update-alternatives or try to explicitly use the 3.7 version.

nunojusto commented 4 years ago

@ixje In easy wording: RUN - runs the command and makes a new layer for the image with the output of the command. So it will be inside the image and already done. CMD - It's used to set a default command when the container starts. So, with a default start of the container, without any "docker run" parameter, that command will be done. But with this, you can override it, with "docker run" parameters when starting the container. Because sometimes we need containers less strict.

So RUN is immutable and written inside the image, and CMD is running inside an already started container.

Is that good for an explanation?

ixje commented 4 years ago

immutable vs mutable, that makes sense. Thanks @nunojusto

What I don't understand is; why would changing to the mutable version fix the issue the user is reporting. I think what @LysanderGG is saying makes more sense, no? e.g. change it to

RUN pip3.7 install -e .
LysanderGG commented 4 years ago

I think it fixes the build since pip install is not run but the image will not work. Not tested though.

ixje commented 4 years ago

With the change made to the PR I now get this

Eriks-MacBook-Air:docker erik$ docker build --no-cache -f Dockerfile -t neopython .
Sending build context to Docker daemon  13.31kB
Step 1/13 : FROM ubuntu:18.04

...

Step 10/13 : RUN python3.7m get-pip.py
 ---> Running in fbea1dcad085
Collecting pip
  Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-19.2.3
Removing intermediate container fbea1dcad085
 ---> c2c538957394
Step 11/13 : RUN pip3.7 install -e .
 ---> Running in 8ef8c3335e12
Obtaining file:///neo-python
Collecting aenum==2.1.2 (from neo-python==0.9.0)

...

Step 13/13 : CMD /bin/bash
 ---> Running in 356d066d4e0a
Removing intermediate container 356d066d4e0a
 ---> 87502f8f993c
Successfully built 87502f8f993c
Successfully tagged neopython:latest

@volekerb can you please verify it works for you? I previously tested it for the issue you referenced (#1008) and it was working back then. Would be great if you can verify the change.

volekerb commented 4 years ago

@ixje yes this fix works for me! Thank you!

Step 13/13 : CMD /bin/bash
 ---> Using cache
 ---> 6f682fde6ccd
Successfully built 6f682fde6ccd
ixje commented 4 years ago

Great. Thanks for reporting and getting the discussion started :)

ixje commented 4 years ago

@volekerb could you merge the latest development branch and add an entry in CHANGELOG.rst? Then we're complete for merging here. Thanks.

volekerb commented 4 years ago

@ixje in sync with development and update CHANGELOG.

ixje commented 4 years ago

@volekerb it does not look like you first merged the latest development branch.

I had to fix (among others) the version from 0.8.6-dev to 0.9.1-dev after a bit of rushed/messy manual release. Please merge that so you can put an entry in this section: https://github.com/CityOfZion/neo-python/blob/8cffda71bfdca76688e3e9c1c52f234e7678bb75/CHANGELOG.rst#091-dev-in-progress

Thanks

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 85.305% when pulling 9c979fe68f60e89b080ca07fd78fc2a0f894ca21 on volekerb:origin/fix_docker into 8cffda71bfdca76688e3e9c1c52f234e7678bb75 on CityOfZion:development.

ixje commented 4 years ago

👍

selimerunkut commented 4 years ago

Hi,

somehow the lines

RUN wget https://bootstrap.pypa.io/get-pip.py

RUN python3.7m get-pip.py

RUN pip3.7 install -e .

causing the error:

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.7m -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/neo-python/setup.py'"'"'; __file__='"'"'/neo-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info
         cwd: /neo-python/
    Complete output (12 lines):
    Traceback (most recent call last):
      File "/neo-python/setup.py", line 8, in <module>
        from pip._internal.download import PipSession
    ModuleNotFoundError: No module named 'pip._internal.download'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/neo-python/setup.py", line 10, in <module>
        from pip.req import parse_requirements
    ModuleNotFoundError: No module named 'pip.req'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Changing the lines to:

RUN apt install python3.7

RUN python3.7 -m pip install -e .

builds the container just fine