neozhaoliang / pywonderland

A tour in the wonderland of math with python.
MIT License
4.18k stars 346 forks source link

Run pywonderland inside a Docker container #7

Closed cclauss closed 7 years ago

cclauss commented 7 years ago

Q: How can I work with pywonderland on my computer without installing all of the required libraries and modules into my operating system?

A: Docker will allow you to create a Linux container running Python 3 where we can install pywonderland and all of its dependencies.

neozhaoliang commented 7 years ago

@cclauss : Thanks for this pr. I tested docker on my computer (Ubuntu 16.04) and it reported some errors. May be it's because of some problems in my operating system configs. I'll try it later.

By the way, installing the numba and pygraphviz modules requires some other dependencies and exporting environment variables, may vary depending on the system.

cclauss commented 7 years ago

Did the errors prevent four_images.sh from running? The operating system that we are installing numba onto in the container is Debian 8 (Jessie).

neozhaoliang commented 7 years ago

No, I ran sh four_images.sh, it rendered three images and stopped with an error. Maybe it's because some configs in my system conflicted with it. I'll try it again tomorrow.

neozhaoliang commented 7 years ago

It still reports errors (I'm sure my system is ok and docker is installed on my computer):

... 
...
...
File "/usr/local/lib/python2.7/dist-packages/numba/typing/context.py", line 590, in load_additional_registries
    from . import (cffi_utils, cmathdecl, enumdecl, listdecl, mathdecl,
  File "/usr/local/lib/python2.7/dist-packages/numba/typing/cffi_utils.py", line 17, in <module>
    ffi = cffi.FFI()
  File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 59, in __init__
    "version mismatch, %s != %s" % (backend.__version__, __version__)
AssertionError: version mismatch, 1.5.2 != 1.7.0
There should be four .png files when this script ends.
e8-pattern.png  modulargroup.png  penrose.png
Copying all .png files to the shared directory.
cp: 目标'/data_to_host' 不是目录

It seems that there is a mismatch of the version 1.5.2!=1.7.0

cclauss commented 7 years ago

Please try again with this new version where we pip install cffi==1.5.2

That makes the numba errors disappear!

neozhaoliang commented 7 years ago

no, I uninstalled my cffi 1.7.0 and then installed cffi1.5.2, it reports the same error as above.

cclauss commented 7 years ago

Can you try changing:

cclauss commented 7 years ago

In your terminal try: python3 -c "import cffi ; print(cffi.__version__)"

If that returns 1.5.2 then you might want to upgrade cffi with: pip3 install --upgrade cffi

neozhaoliang commented 7 years ago

I have fixed this problem, it's not because of my cffi lib, I can run all the scripts with python3 but not mandelbrot.py with python2.7 (I have just changed to a new computer, the code runs on my old laptop and I haven't test it on this new one yet). It's because of my numba lib with python2.7. There's no problem with your .sh script.

But when I run docker following the six steps in your .md file, it reports:

docker build -t pywonderland .
Sending build context to Docker daemon 1.329 MB
Step 1 : FROM python:3
3: Pulling from library/python
ad74af05f5a2: Pull complete 
2b032b8bbe8b: Pull complete 
a9a5b35f6ead: Pull complete 
3245b5a1c52c: Pull complete 
032924b710ba: Pull complete 
0d7cffe4bfd7: Pull complete 
450f5ea3e7ea: Pull complete 
b1dca9769b8b: Pull complete 
Digest: sha256:81a1ab6955f8a17045fb4c2866b21c91445837507e86d489b03744557e6ed209
Status: Downloaded newer image for python:3
 ---> 968120d8cbe8
Step 2 : LABEL "repo" "https://github.com/neozhaoliang/pywonderland"
 ---> Running in 0b328dd90c52
 ---> e2c04eeb92cc
Removing intermediate container 0b328dd90c52
Step 3 : WORKDIR /usr/src/app
 ---> Running in 820b3e1d097a
 ---> 4ed2f12c9ea5
Removing intermediate container 820b3e1d097a
Step 4 : COPY . .
 ---> ac9152553ade
Removing intermediate container a21ec6cf810c
Step 5 : RUN apt-get update  && apt-get upgrade --yes  && apt-get install libcairo2-dev ImageMagick povray --yes  && pip install cairocffi numpy matplotlib palettable pillow pyglet scipy tqdm vapory  && echo "Starting of numba... (get a coffee)"  && pip install numba  && echo "====================================================================================================="  && echo "Please type: docker run -it -v ~/data_from_docker:/data_to_host --rm --name pywonderland pywonderland"
 ---> Running in b6caa25ee679
Ign http://deb.debian.org jessie InRelease
Get:1 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:2 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:3 http://deb.debian.org jessie Release.gpg [2373 B]
Get:4 http://deb.debian.org jessie-updates/main amd64 Packages [17.8 kB]
Get:5 http://deb.debian.org jessie Release [148 kB]
Get:6 http://security.debian.org jessie/updates/main amd64 Packages [539 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9065 kB]
Fetched 9980 kB in 7s (1384 kB/s)
W: Failed to fetch http://deb.debian.org/debian/dists/jessie/main/binary-amd64/Packages  Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get update  && apt-get upgrade --yes  && apt-get install libcairo2-dev ImageMagick povray --yes  && pip install cairocffi numpy matplotlib palettable pillow pyglet scipy tqdm vapory  && echo "Starting of numba... (get a coffee)"  && pip install numba  && echo "====================================================================================================="  && echo "Please type: docker run -it -v ~/data_from_docker:/data_to_host --rm --name pywonderland pywonderland"' returned a non-zero code: 100

Obviously it's downloading from the debian distribution jessie not ubuntu16.04.

cclauss commented 7 years ago

Did this happen on just one build attempt or on multiple build attempts?

The OS that runs inside the Docker container is Debian Jessie and your OS that runs outside the container is ubuntu16.04. The Dockerfile is trying to update, upgrade, and install on Juessie inside the container which is what we want.

neozhaoliang commented 7 years ago

I run the build command several times and it always happened. I find this issue maybe useful.

If it's not that easy to get docker running, I suggest not add this feature (maybe it takes less time to install the python dependencies ...). A bash script would be fine.

cclauss commented 7 years ago

Is your docker up-to-date?

neozhaoliang commented 7 years ago

my docker version is 1.12.6

cclauss commented 7 years ago

Try this version with the apt-get clean added.

If that does not work then I would recommend that you upgrade your docker v1.12 because after that there was a v1.13, then a v17.3, and now the current v17.6 https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/

neozhaoliang commented 7 years ago

I updated my docker to 17.06 and run docker run hello-world, it works correctly, but running docker build -t pywonderland . reports the same error.

cclauss commented 7 years ago

You did that with the latest commit https://github.com/neozhaoliang/pywonderland/pull/7/commits/f9ea90acd1f7d04e5ed3b15f612131a1639266c8 ?

neozhaoliang commented 7 years ago

Yes.

neozhaoliang commented 7 years ago

I'm a newbie to docker so I cannot help you much debug it, Maybe we can left this pr here until we fix it?

cclauss commented 7 years ago

Close for now...