Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generated windows exe (pyinstaller) could not load _cffi_backend

I am trying to generate executable(x86) with pyinstaller(3.0) on windows7(x64). I have installed cffi and other needed packages with pip. I can import cffi and _cffi_backend module successfully from command line:

>>> import cffi
>>> import _cffi_backend
>>> cffi.__file__
'C:\\Program Files (x86)\\Python27\\lib\\site-packages\\cffi\\__init__.pyc'
>>> _cffi_backend.__file__
'C:\\Program Files (x86)\\Python27\\lib\\site-packages\\_cffi_backend.pyd'

>

While trying to run generated executable I got error below:

  File "C:\Program Files (x86)\Python27\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 13, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
  File "c:\program files (x86)\python27\lib\site-packages\PyInstaller-3.0-py2.7.egg\PyInstaller\loader\pyimod03_importers.py", line 517, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: No module named _cffi_backend

You may see full startup log here.

By the way, I have compiled libcffi library with mingw and got a DLL file. Then copied to one of the library path and I got same error on application startup again.

I do not know why _cffi_backend library could not be loaded on application startup even it exists and in python path. I am not good at python and unfortunately I am stuck on this almost 2 days, any suggestion and guidence will be appreciated.

Thanks.

like image 831
mgundes Avatar asked Dec 04 '15 00:12

mgundes


People also ask

Why is the .EXE file created by PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Does PyInstaller work on Windows?

PyInstaller supports making executables for Windows, Linux, and macOS, but it cannot cross compile.

Do you need Python to run a PyInstaller EXE?

To your users, the app is self-contained. They do not need to install any particular version of Python or any modules. They do not need to have Python installed at all. The output of PyInstaller is specific to the active operating system and the active version of Python.


1 Answers

Just add --hidden-import=_cffi_backend option when building with pyinstaller.

like image 64
Iansus Avatar answered Oct 31 '22 12:10

Iansus