Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFFI fails in Python (Linux) virtual environment -- attempting to install cryptography package in venv

Installing cffi in the virtual environment encounters errors, but seems to install. Are these errors actually critical, ones that could lead it to fail when installing cryptography (see further below)?

pip install cffi==1.11.5

Downloading/unpacking cffi==1.11.5

Downloading cffi-1.11.5.tar.gz (438kB): 438kB downloaded
Running setup.py (path:/[venv-install-directory]/build/cffi/setup.py) egg_info for package cffi
Downloading/unpacking pycparser (from cffi==1.11.5)
Downloading pycparser-2.18.tar.gz (245kB): 245kB downloaded
Running setup.py (path:/[venv-install-directory]/build/pycparser/setup.py) egg_info for package pycparser
warning: no previously-included files matching 'yacctab.' found under directory 'tests'
warning: no previously-included files matching 'lextab.
' found under directory 'tests'
warning: no previously-included files matching 'yacctab.' found under directory 'examples'
warning: no previously-included files matching 'lextab.
' found under directory 'examples'
Installing collected packages: cffi, pycparser
Running setup.py install for cffi
building '_cffi_backend' extension
gcc -pthread -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/local/lib/libffi-3.2.1/include -I/[venv-install-directory]/include -I/usr/local/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-i686-3.4/c/_cffi_backend.o
gcc -pthread -shared build/temp.linux-i686-3.4/c/_cffi_backend.o -L/usr/local/lib -lffi -o build/lib.linux-i686-3.4/_cffi_backend.cpython-34m.so Could not find .egg-info directory in install record for cffi==1.11.5
Running setup.py install for pycparser
warning: no previously-included files matching 'yacctab.' found under directory 'tests'
warning: no previously-included files matching 'lextab.
' found under directory 'tests'
warning: no previously-included files matching 'yacctab.' found under directory 'examples'
warning: no previously-included files matching 'lextab.
' found under directory 'examples'
Build the lexing/parsing tables
Could not find .egg-info directory in install record for pycparser (from cffi==1.11.5)
Successfully installed cffi pycparser
Cleaning up...

This problem is perplexing because it works on my local system, but when creating a virtual environment, the following error occurs during the attempted install of cryptography:

  File "[path-to-venv]/build/cryptography/src/_cffi_src/utils.py", line 57, in build_ffi
   ffi = FFI()

   File "[path-to-venv]/lib/python3.4/site-packages/cffi/api.py", line 46, in __init__
    import _cffi_backend as backend

ImportError: [path-to-venv]/lib/python3.4/site-packages/_cffi_backend.cpython-34m.so: undefined symbol: __syscall_error

A virtual environment literally creates a copy of the local environment, doesn't it?

So how is "_cffi_backend" not working in the virtual environment, when there's no problem on the system install itself? I don't see how this could happen in the first place.

Has anyone successfully dealt with a problem like this one? If you have ideas or a solution, please be specific since I've already spent quite a few hours trying solutions that haven't worked so far.

Among other things, I've already tried compiling and installing libffi from source before creating the virtual environment: https://sourceware.org/libffi/

Are there other alternatives for creating virtual environments that don't require re-installing every package -- i.e. where can just use your existing installed setup and copy it directly into the virtual environment (or a similar way that avoids falling into dependency hell)?

This seems like a simple issue to solve once you have a grasp of the actual problem. If I can't figure this out, I can't deploy my project since it crucially depends on cryptography. So thanks in advance for any ideas you might have that could help fix this issue.

like image 495
murmur0m Avatar asked May 07 '18 00:05

murmur0m


1 Answers

The answer in this case was to upgrade pip -- inside the virtual environment.

Complete instructions:

  1. create the virtual environment.

    python3.4 -m venv [venv_name_here]

  2. enter the virtual environment.

    cd [venv_name_here]

  3. activate the virtual environment.

    source bin/activate

4. upgrade pip.

pip install --upgrade pip

  1. install setuptools.

    pip install setuptools==39.1.0

  2. install pyparser.

    pip install pyparser==1.0
    pip install pyparsing==2.1.0

  3. install cffi.

    pip install cffi==1.11.5

  4. install cryptography.

    pip install cryptography==2.2.2

Completes installation perfectly, with no errors.

Note that you may need to change version numbers, depending on the output of the "pip freeze" command (i.e. look at your 'requirements.txt' file):

pip freeze -l > requirements.txt

like image 133
murmur0m Avatar answered Oct 17 '22 23:10

murmur0m