virtualenv with kivy

Asked

Viewed 706 times

3

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

I’ll have Kivy installed:

pip install kivy

Only 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/

Which dependencies are missing?

  • But this solves the problem of dependencies in the virtual environment?

  • I did it and still have problems to use kivy in the virtual environment. Any more ideas/suggestions?

3 answers

1

So - the PIP inside and a virtualenv solves all of the Python package applications inside - but some Python packages rely on compiling C code for their installation, others rely on native system libraries - and this is independent of being inside Virtualenv. (Yes, it is even possible to place native C biblitoecas in different versions within virtualenv, but in general it is not necessary).

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

(In other Linux distributions, the idea is the same - in the Folder for example, the command to install a package’s departments is dnf builddep <pacote>)

  • So @jsbueno , the point is that I installed kivy using sudo apt install python-kivy and everything works perfectly, outside the virtual environment, which leads me to believe that the dependencies are installed. Already in the virtual environment, I can not execute any kivy code, always returns the errors I mentioned in the question.

  • No - it’s exact like I wrote - when you make a apt-get install python-kivy ( and even python-kivy-dev) - it installs the pre-compiled version - not the resources the system needs to compile kivy. When you do a "Pip install" on the virtulenv it downloads the source code to compile oskivy on your machine - and there, the necessary tools and biblitoecas have to be installed on the system.

  • I’m beginning to understand how @jsbueno works. Thanks for the help. Now, when running apt-get build-dep python python-kivy I face the return E: Você deve colocar algumas URIs 'source' em seu sources.list. Any more information?

1


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

The very one official Kivy website provided the necessary information. What made me confused was having to install packages on the (global) system 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 that Kivy could work (even in the virtual environment), it was enough to 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 then on, I stopped the virtual environment, which I had already created with the virtualenv, and executed the commands:

pip install cython==0.23
pip install kivy

And that’s it! Thank you very much for the help of everyone who collaborated with my learning. Hugs.

-2

So, I went through these problems, installing and testing the operation, this was the process I went through to be able to use kivy and compile it for mobile. I created a tutorial which is functional.

LINK GITHUB

and ready just run your program and compile!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.