Aditya
Aditya

Reputation: 3158

Set up cassandra driver (python) in Docker

I used a docker file several months ago that (1) uses base ubuntu image, (2) installs miniconda python distribution, (3) installs some python libraries using miniconda, (4) runs following commands to set up cassandra-driver for python.

RUN pip install --upgrade pip
RUN pip install cassandra-driver

This worked perfectly six months ago. But now I'm getting this exception.

Step 13 : RUN pip install cassandra-driver
 ---> Running in ba9955650d7c
Collecting cassandra-driver
  Downloading cassandra-driver-3.0.0.tar.gz (186kB)
    Complete output from command python setup.py egg_info:
    warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.h' under directory 'Cython/Debugger/Tests'
    warning: no files found matching '*.pxd' under directory 'Cython/Utility'
    unable to execute 'gcc': No such file or directory
    Unable to find pgen, not compiling formal grammar.
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-0XzsPv/cassandra-driver/setup.py", line 375, in <module>
        run_setup(None)
      File "/tmp/pip-build-0XzsPv/cassandra-driver/setup.py", line 373, in run_setup
        **kw)
      File "/miniconda/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/dist.py", line 268, in __init__
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/dist.py", line 312, in fetch_build_eggs
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/pkg_resources/__init__.py", line 846, in resolve
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/pkg_resources/__init__.py", line 1091, in best_match
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/pkg_resources/__init__.py", line 1103, in obtain
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/dist.py", line 379, in fetch_build_egg
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/command/easy_install.py", line 639, in easy_install
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/command/easy_install.py", line 669, in install_item
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/command/easy_install.py", line 852, in install_eggs
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/command/easy_install.py", line 1080, in build_and_install
      File "/miniconda/lib/python2.7/site-packages/setuptools-19.1.1-py2.7.egg/setuptools/command/easy_install.py", line 1068, in run_setup
    distutils.errors.DistutilsError: Setup script exited with error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-0XzsPv/cassandra-driver
The command '/bin/sh -c pip install cassandra-driver' returned a non-zero code: 1

What might be going wrong? Is the installation package broken or I'm not doing it right?

Upvotes: 4

Views: 2370

Answers (2)

Andy Tolbert
Andy Tolbert

Reputation: 11638

The python cassandra-driver now uses Cython extensions by default since version 2.7.0, but there is an escape hatch for those who don't have easy access to the cython distribution or don't need it which might be a good option for you as well. The cython extensions do offer a boon to performance, but it might not be suitable for a lot of cases (especially where you are not doing high throughput).

From the install documentation:

By default, this package uses Cython to optimize core modules and build custom extensions. This is not a hard requirement, but is engaged by default to build extensions offering better performance than the pure Python implementation.

This build phase can be avoided using the build switch, or an environment variable:

python setup.py install --no-cython
-or-
pip install --install-option="--no-cython" <spec-or-path>

Alternatively, an environment variable can be used to switch this option regardless of context:

CASS_DRIVER_NO_CYTHON=1 <your script here>

Upvotes: 5

Aleksandr Kovalev
Aleksandr Kovalev

Reputation: 3740

In order to install cassandra-driver you need to compile some C source files however you don't have gcc inside your container:

unable to execute 'gcc': No such file or directory

Try to install gcc and python-dev packages before installing cassandra-driver:

RUN apt-get update \
  && apt-get install -y --no-install-recommends \
    python-dev \
    gcc \
  && rm -rf /var/lib/apt/lists/*

Upvotes: 3

Related Questions