virtualenv with kivy

2

Using Ubuntu 16.04, I installed virtualenv and created a virtual environment.

In this virtual environment I installed Cython using:

pip install cython==0.23

Kivy install command:

pip install kivy

But it returns a lot of errors, among them:

/tmp/pip-build-RTmWI8/kivy/kivy/graphics/opengl.c:4:20: fatal error: Python.h: Arquivo ou diretório não encontrado
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Command "/home/usuario/testeKivy/teste1/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-RTmWI8/kivy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ZZtk3g-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/usuario/testeKivy/teste1/include/site/python2.7/kivy" failed with error code 1 in /tmp/pip-build-RTmWI8/

What dependencies are missing?

    
asked by anonymous 04.09.2016 / 21:17

2 answers

1

Well, after learning a little more by reading the comments, I realized that solving the dependency problem was "easy".

The Kivy's official website provided the necessary information. What made me confused was having to install packages on the system (global) if my intention was to use Kivy in a virtual environment with virtualenv . When I learned that it was necessary to install packages globally so Kivy could work (even in the virtual environment), just follow the installation list :

sudo apt-get install -y \
    python-pip \
    build-essential \
    git \
    python \
    python-dev \
    ffmpeg \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    libsdl2-ttf-dev \
    libportmidi-dev \
    libswscale-dev \
    libavformat-dev \
    libavcodec-dev \
    zlib1g-dev

From there, I accessed the virtual environment, which I had already created with virtualenv , and executed the commands:

pip install cython==0.23
pip install kivy
And that's it! Thank you for the help of everyone who helped with my learning. Hugs.

    
08.09.2016 / 06:18
1
So - the PIP inside and a virtualenv solves all the Python packet dependencies in there - but some Python packages depend on compiling C code for their installation, others rely on native system libraries - and that is not true of Virtualenv . (Yes, it's even possible to put native scripts in C in different versions, inside virtualenv, but in general it's not necessary).

In this case, you have to complete the installation of Ubuntu with the necessary tools for compiling software - start with apt-get install build-essential - and already enjoy and wrap a apt-get build-dep python python-kivy . You may have to install the build-dep for some other packages that you want to install inside vitualenv as well) - the special command build-dep of APT brings all packages - including the "* dev" required to compile the target package from the sources - if the system package was used. Even though inside a virtualenv you are not compiling a library that will be available to the whole system, its dependencies are the same - and it takes advantage of the dependencies installed on the system.

(In other Linux distributions, the idea is the same - in fedora for example, the command to install the dependencies of a package is dnf builddep <pacote> )

    
05.09.2016 / 10:22