Install Cython with python3 in Docker

7,010

I have found that the solution was to use pip3 to run Cython install as well as python3 to run the setup.py of the library, so:

RUN apt-get update && apt-get install -y \
    python3-pip

and

RUN \ 
    pip3 install --no-cache-dir Cython

and the library layer

RUN \
    cd lib && \
    python3 setup.py

The last one could have been pip3 install . to install globally using pip3.

This time doing

RUN python3 -c "import Cython; print(Cython.__version__)"

I had Cython there: 0.25.2

Share:
7,010

Related videos on Youtube

loretoparisi
Author by

loretoparisi

Computer Engineer. Technical Director of Machine Learning @musixmatch

Updated on September 18, 2022

Comments

  • loretoparisi
    loretoparisi over 1 year

    I'm using a Docker image from tensorflow with python3:

    FROM tensorflow/tensorflow:latest-gpu-py3
    

    I need Cython for a 3rd party library to be there, so I do

    RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
        python get-pip.py && \
        rm get-pip.py
    
    RUN \ 
        pip install --no-cache-dir Cython
    

    The problem is that after that I can see Cython from python, but not from python3:

    root@fdb5bb783cf9:/darkflow# python3 -c "import Cython; print(Cython.__version__)"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named 'Cython'
    root@fdb5bb783cf9:/darkflow# python -c "import Cython; print(Cython.__version__)"
    0.25.2
    
    • OscarAkaElvis
      OscarAkaElvis about 7 years
      Are you sure the image you are using has python3? is tagged as it is... but I repeat, are you sure?
    • loretoparisi
      loretoparisi about 7 years
      Thanks I have just realized I have missed something: apt-get install python3-pip, and pip3 install --no-cache-dir Cython, after that it worked!
    • OscarAkaElvis
      OscarAkaElvis almost 7 years
      Ok so put the answer yourself and mark it as resolved.