Repository: pyinstaller/pyinstaller

Issue:
hook for cryptography 1.0 - changes in __cffi__ bindings
```
python version:3.4.3
os:windows 10(64bit)
pyinstaller installation:
1.down https://github.com/pyinstaller/pyinstaller/archive/python3.zip 
2.pip install python3.zip
3.setup successful
```

I am in client.py:

from OpenSSL import SSL, crypto
import sys, os, socket

```
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py", line 302, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py", line 302, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\rand.py", line 11, in <module>
    from OpenSSL._util import (
  File "C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py", line 302, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\_util.py", line 6, in <module>
    from cryptography.hazmat.bindings.openssl.binding import Binding
  File "C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py", line 302, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 60, in <module>
    class Binding(object):
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 109, in Binding
    libraries=_get_libraries(sys.platform)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\utils.py", line 68, in build_ffi_for_binding
    __import__(module_name)
ImportError: No module named 'cryptography.hazmat.bindings.openssl.aes'
```

I try to:

```
pyinstaller --onefile client.py --hidden-import=cryptography.hazmat.bindings.openssl.aes \
    --hidden-import=cryptography.hazmat.bindings.openssl.asn1 \
    --hidden-import=cryptography.hazmat.bindings.openssl.bignum \
    --hidden-import=cryptography.hazmat.bindings.openssl.bio \
    --hidden-import=cryptography.hazmat.bindings.openssl.cmac \
    --hidden-import=cryptography.hazmat.bindings.openssl.cms \
    --hidden-import=cryptography.hazmat.bindings.openssl.conf \
    --hidden-import=cryptography.hazmat.bindings.openssl.crypto \
    --hidden-import=cryptography.hazmat.bindings.openssl.dh \
    --hidden-import=cryptography.hazmat.bindings.openssl.dsa \
    --hidden-import=cryptography.hazmat.bindings.openssl.ec \
    --hidden-import=cryptography.hazmat.bindings.openssl.ecdh \
    --hidden-import=cryptography.hazmat.bindings.openssl.ecdsa \
    --hidden-import=cryptography.hazmat.bindings.openssl.engine \
    --hidden-import=cryptography.hazmat.bindings.openssl.err \
    --hidden-import=cryptography.hazmat.bindings.openssl.evp \
    --hidden-import=cryptography.hazmat.bindings.openssl.hmac \
    --hidden-import=cryptography.hazmat.bindings.openssl.nid \
    --hidden-import=cryptography.hazmat.bindings.openssl.objects \
    --hidden-import=cryptography.hazmat.bindings.openssl.opensslv \
    --hidden-import=cryptography.hazmat.bindings.openssl.osrandom_engine \
    --hidden-import=cryptography.hazmat.bindings.openssl.pem \
    --hidden-import=cryptography.hazmat.bindings.openssl.pkcs7 \
    --hidden-import=cryptography.hazmat.bindings.openssl.pkcs12 \
    --hidden-import=cryptography.hazmat.bindings.openssl.rand \
    --hidden-import=cryptography.hazmat.bindings.openssl.rsa \
    --hidden-import=cryptography.hazmat.bindings.openssl.ssl \
    --hidden-import=cryptography.hazmat.bindings.openssl.x509 \
    --hidden-import=cryptography.hazmat.bindings.openssl.x509name \
    --hidden-import=cryptography.hazmat.bindings.openssl.x509v3 \
    --hidden-import=cryptography.hazmat.bindings.openssl.x509_vfy
44 INFO: wrote D:\hj_workflow\cmdb\client\test_one_exe\client.spec
45 INFO: Testing for ability to set icons, version resources...
51 INFO: ... resource update available
52 INFO: UPX is not available.
54 INFO: Extending PYTHONPATH with D:\hj_workflow\cmdb\client\test_one_exe
55 INFO: checking Analysis
56 INFO: building because out00-Analysis.toc missing or bad
56 INFO: Creating base_library.zip for Python 3
935 INFO: running Analysis out00-Analysis.toc
1055 INFO: Analyzing client.py
2421 INFO: Analyzing C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\_pyi_bootstrap.py
2429 INFO: Analyzing C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py
2432 INFO: Analyzing C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_archive.py
2434 INFO: Analyzing C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_carchive.py
2437 INFO: Analyzing C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_os_path.py
2437 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.aes'
2438 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.asn1'
2439 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.bignum'
2440 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.bio'
2440 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.cmac'
2441 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.cms'
2442 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.conf'
2442 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.crypto'
2443 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.dh'
2444 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.dsa'
2444 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.ec'
2445 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.ecdh'
2446 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.ecdsa'
2446 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.engine'
2447 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.err'
2448 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.evp'
2449 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.hmac'
2449 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.nid'
2450 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.objects'
2450 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.opensslv'
2451 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.osrandom_engine'
2451 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.pem'
2452 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.pkcs7'
2453 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.pkcs12'
2453 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.rand'
2454 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.rsa'
2454 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.ssl'
2455 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.x509'
2456 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.x509name'
2457 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.x509v3'
2457 INFO: Analyzing hidden import 'cryptography.hazmat.bindings.openssl.x509_vfy'
2458 INFO: Hidden import 'codecs' has been found otherwise
2459 INFO: Hidden import 'encodings' has been found otherwise
2459 INFO: Looking for import hooks ...
2466 INFO: Processing hook   hook-encodings.py
2596 INFO: Processing hook   hook-pydoc.py
2597 INFO: Processing hook   hook-distutils.py
2600 INFO: Processing hook   hook-xml.py
2621 INFO: Processing hook   hook-xml.sax.py
2622 INFO: Processing hook   hook-site.py
2626 INFO: Processing hook   hook-sysconfig.py
2628 INFO: Processing hook   hook-pywintypes.py
2719 INFO: Processing hook   hook-win32com.client.py
2720 INFO: Processing hook   hook-win32ui.py
2720 INFO: Processing hook   hook-win32com.py
2740 INFO: Processing hook   hook-pythoncom.py
2793 INFO: Processing hook   hook-setuptools.py
2803 INFO: Analyzing run-time hooks ...
2806 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
2807 INFO: Including run-time hook 'pyi_rth_pkgres.py'
2816 INFO: Looking for dynamic libraries
3550 INFO: Looking for eggs - TODO
3559 INFO: Using Python library C:\WINDOWS\system32\python34.dll
3598 INFO: Warnings written to D:\hj_workflow\cmdb\client\test_one_exe\build\client\warnclient.txt
3599 INFO: checking PYZ
3602 INFO: building because toc changed
3602 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
4197 INFO: checking PKG
4198 INFO: building because D:\hj_workflow\cmdb\client\test_one_exe\build\client\out00-PYZ.pyz changed
4198 INFO: building PKG (CArchive) out00-PKG.pkg
7080 INFO: checking EXE
7081 INFO: rebuilding out00-EXE.toc because pkg is more recent
7081 INFO: building EXE from out00-EXE.toc
7083 INFO: Appending archive to EXE D:\hj_workflow\cmdb\client\test_one_exe\dist\client.exe
```

build log：

```
no module named _dummy_threading - imported by dummy_threading
no module named org - imported by copy, org.python
no module named org.PyStringMap - imported by org
no module named pwd - imported by posixpath, tarfile, shutil, http.server, webbrowser, distutils.util, distutils.archive_util, getpass
no module named os.path - imported by os, pkgutil, shutil, py_compile, unittest.util, cffi.ffiplatform, distutils.file_util, pkg_resources, sysconfig, setuptools.utils, pycparser.ply.yacc, pycparser.ply.lex, C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_carchive.py
no module named _posixsubprocess - imported by subprocess, multiprocessing.util
no module named grp - imported by tarfile, shutil, distutils.archive_util
no module named urllib.pathname2url - imported by urllib
no module named urllib.splittag - imported by urllib
no module named urllib.url2pathname - imported by urllib
no module named termios - imported by tty, getpass
no module named vms_lib - imported by platform
no module named java.lang - imported by platform, xml.sax._exceptions
no module named java - imported by platform, java.lang
no module named java.System - imported by java
no module named _scproxy - imported by urllib.request
no module named org.python.core - imported by xml.sax
no module named org.python - imported by pickle, org.python.core
no module named org.python.PyStringMap - imported by org.python
no module named _frozen_importlib - imported by importlib, pyi_archive, pyi_importers, C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_importers.py, C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_archive.py
no module named __main__ - imported by bdb, pdb, pkg_resources, rlcompleter
no module named readline - imported by cmd, code, pdb, site, rlcompleter
no module named collections.OrderedDict - imported by collections
no module named collections.namedtuple - imported by collections
no module named collections.ChainMap - imported by collections
no module named ce - imported by os
no module named posix - imported by os, pyi_os_path, C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_os_path.py
no module named multiprocessing.set_start_method - imported by multiprocessing
no module named multiprocessing.get_start_method - imported by multiprocessing
no module named multiprocessing.TimeoutError - imported by multiprocessing
no module named multiprocessing.get_context - imported by multiprocessing
no module named multiprocessing.AuthenticationError - imported by multiprocessing
no module named multiprocessing.BufferTooShort - imported by multiprocessing
no module named _sysconfigdata - imported by sysconfig
no module named packaging.specifiers - imported by pkg_resources
no module named packaging - imported by pkg_resources
no module named urlparse - imported by setuptools.compat, pkg_resources
no module named win32com.client._get_good_object_ - imported by win32com.client
no module named win32com.client.Dispatch - imported by win32com.client
no module named  - imported by C:\Python34\lib\site-packages\pyinstaller-3.0.dev0-py3.4.egg\PyInstaller\loader\pyi_carchive.py
no module named .pyi_archive - imported by 
no module named usercustomize - imported by site
no module named sitecustomize - imported by site
no module named setuptools_svn - imported by setuptools.command.egg_info
no module named org.python.modules - imported by setuptools.sandbox
no module named setuptools.setup - imported by setuptools
no module named wincertstore - imported by setuptools.ssl_support
no module named backports.ssl_match_hostname - imported by setuptools.ssl_support
no module named setuptools.Command - imported by setuptools
no module named urllib2 - imported by setuptools.compat
no module named SimpleHTTPServer - imported by setuptools.compat
no module named BaseHTTPServer - imported by setuptools.compat
no module named httplib - imported by setuptools.compat
no module named htmlentitydefs - imported by setuptools.compat
no module named StringIO - imported by six, setuptools.compat
no module named ConfigParser - imported by setuptools.compat
no module named __builtin__ - imported by setuptools.compat
no module named cStringIO - imported by cffi.ffiplatform
no module named cffi.__version_verifier_modules__ - imported by cffi
no module named cffi.__version__ - imported by cffi
no module named thread - imported by cffi.lock, cffi.cparser, OpenSSL.crypto
no module named md5 - imported by pycparser.ply.yacc
no module named cPickle - imported by pycparser.ply.yacc
no module named ply - imported by pycparser.ply.yacc
no module named lex - imported by pycparser.ply.yacc
no module named cffi._pycparser - imported by cffi
no module named dummy_thread - imported by cffi.lock
no module named testing - imported by cffi.recompiler
no module named testing.udir - imported by testing
```



Discussion:
Please provide more information: https://github.com/pyinstaller/pyinstaller/wiki/How-to-Report-Bugs

@htgoebel update 

@mo0feng e.g. you haven't specified what version of additional modules you use and how to install them or what exact version of PyInstaller you use and how it was installed.

@matysek 
thank you!
I am in "https://github.com/pyinstaller/pyinstaller/tree/python3" this branch of version
the download installation.

@mo0feng When you use `--hidden-import=cryptography.hazmat.bindings.openssl.XYZ` does it then work for you?

@mo0feng I fixed the hook-cryptography. Please the updated python3 branch again.

@matysek  

When you use --hidden-import=cryptography.hazmat.bindings.openssl.XYZ does it then work for you?
Re:don't work

I fixed the hook-cryptography. Please the updated python3 branch again.
Re:thank you!

now let me try this python3 branch.

@matysek I use the branch version  encountered an error：

Name: cryptography
Version: 0.9.2
Home-page: https://github.com/pyca/cryptography

```
pyinstaller --onefile client.py
46 INFO: PyInstaller version 3.0dev
47 INFO: wrote D:\hj_workflow\cmdb\new_win_client\client.spec
48 INFO: UPX is not available.
59 INFO: Extending PYTHONPATH with D:\hj_workflow\cmdb\new_win_client
59 INFO: checking Analysis
59 INFO: Building Analysis because out00-Analysis.toc is non existent
59 INFO: Initializing module dependency graph...
61 INFO: Looking for graph hooks ...
62 INFO: Analyzing base_library.zip ...
3197 INFO: running Analysis out00-Analysis.toc
3311 INFO: Analyzing client.py
6299 INFO: Looking for import hooks ...
6303 INFO: Processing hook   hook-setuptools.py
6336 INFO: Processing hook   hook-cryptography.py
[('C:\\Python34\\lib\\site-packages\\cryptography\\_Cryptography_cffi_a8febd48xffc7b1ce.pyd', 'cryptography'), ('C:\\Python34\\lib\\site-packages\\cryptography\\_Cryptography_cffi_b03f9c7x62b488b1.pyd', 'cryptography'), ('C:\\Python34\\lib\\site-packages\\cryptography\\_Cryptography_cffi_c6806e2axd5c405b7.pyd', 'cryptography')]
6390 INFO: Processing hook   hook-win32com.client.py
6390 INFO: Processing hook   hook-site.py
6392 INFO: Processing hook   hook-win32com.py
6439 INFO: Processing hook   hook-encodings.py
6454 INFO: Processing hook   hook-pycparser.py
6657 INFO: Processing hook   hook-pywintypes.py
[('C:\\WINDOWS\\SYSTEM32\\pywintypes34.dll', '.')]
6766 INFO: Processing hook   hook-xml.py
6830 INFO: Processing hook   hook-pythoncom.py
[('C:\\WINDOWS\\SYSTEM32\\pythoncom34.dll', '.')]
6910 INFO: Processing hook   hook-distutils.py
6913 INFO: Processing hook   hook-pydoc.py
6914 INFO: Processing hook   hook-sysconfig.py
6915 INFO: Processing hook   hook-xml.sax.py
6919 INFO: Looking for ctypes DLLs - TODO
6919 INFO: Analyzing run-time hooks ...
6923 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
6924 INFO: Including run-time hook 'pyi_rth_pkgres.py'
6934 INFO: Looking for dynamic libraries
7756 INFO: Looking for eggs - TODO
7877 INFO: Using Python library C:\WINDOWS\system32\python34.dll
7888 INFO: Warnings written to D:\hj_workflow\cmdb\new_win_client\build\client\warnclient.txt
7898 INFO: checking PYZ
7898 INFO: Building PYZ because out00-PYZ.toc is non existent
7898 INFO: Building PYZ (ZlibArchive) D:\hj_workflow\cmdb\new_win_client\build\client\out00-PYZ.pyz
8191 INFO: checking PKG
8191 INFO: Building PKG because out00-PKG.toc is non existent
8192 INFO: Building PKG (CArchive) out00-PKG.pkg
8385 WARNING: One binary added with two internal names. C:\WINDOWS\SYSTEM32\pywintypes34.dll was placed at .\pywintypes34.dll previously.
11392 INFO: Bootloader C:\Python34\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
11392 INFO: checking EXE
11392 INFO: Building EXE because out00-EXE.toc is non existent
11392 INFO: Building EXE from out00-EXE.toc
11393 INFO: Onefile Mode - Embedding Manifest into EXE file
11396 INFO: Updating manifest in C:\Users\User\AppData\Local\Temp\tmpyt5rm5ia
11397 INFO: Updating resource type 24 name 1 language 0
11440 INFO: Appending archive to EXE D:\hj_workflow\cmdb\new_win_client\dist\client.exe
```

Run:

```
D:\hj_workflow\cmdb\new_win_client\dist\client.exe
WARNING: file already exists but should not: C:\Users\User\AppData\Local\Temp\_MEI84642\pywintypes34.dll
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\rand.py", line 11, in <module>
    from OpenSSL._util import (
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\_util.py", line 6, in <module>
    from cryptography.hazmat.bindings.openssl.binding import Binding
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 60, in <module>
    class Binding(object):
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 109, in Binding
    libraries=_get_libraries(sys.platform)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\utils.py", line 68, in build_ffi_for_binding
    __import__(module_name)
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\osrandom_engine.py", line 10, in <module>
    os.path.dirname(__file__), "src/osrandom_engine.h"
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI84642\\cryptography\\hazmat\\bindings\\openssl\\src/osrandom_engine.h'
client returned -1
```

**Update cryptography to 1.0**
Name: cryptography
Version: 1.0
Home-page: https://github.com/pyca/cryptography

```
pyinstaller --console --onefile client.py
47 INFO: PyInstaller version 3.0dev
48 INFO: wrote D:\hj_workflow\cmdb\new_win_client\client.spec
50 INFO: UPX is not available.
52 INFO: Extending PYTHONPATH with D:\hj_workflow\cmdb\new_win_client
53 INFO: checking Analysis
53 INFO: Building Analysis because out00-Analysis.toc is non existent
53 INFO: Initializing module dependency graph...
55 INFO: Looking for graph hooks ...
57 INFO: Analyzing base_library.zip ...
3215 INFO: running Analysis out00-Analysis.toc
3348 INFO: Analyzing client.py
4076 INFO: Looking for import hooks ...
4080 INFO: Processing hook   hook-pydoc.py
4081 INFO: Processing hook   hook-win32com.py
4133 INFO: Processing hook   hook-cryptography.py
[]
4136 INFO: Processing hook   hook-win32com.client.py
4137 INFO: Processing hook   hook-pywintypes.py
[('C:\\WINDOWS\\SYSTEM32\\pywintypes34.dll', '.')]
4221 INFO: Processing hook   hook-pythoncom.py
[('C:\\WINDOWS\\SYSTEM32\\pythoncom34.dll', '.')]
4309 INFO: Processing hook   hook-xml.py
4562 INFO: Processing hook   hook-encodings.py
4579 INFO: Processing hook   hook-distutils.py
4581 INFO: Processing hook   hook-xml.sax.py
4584 INFO: Looking for ctypes DLLs - TODO
4584 INFO: Analyzing run-time hooks ...
4587 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
4596 INFO: Looking for dynamic libraries
5337 INFO: Looking for eggs - TODO
5338 INFO: Using Python library C:\WINDOWS\system32\python34.dll
5347 INFO: Warnings written to D:\hj_workflow\cmdb\new_win_client\build\client\warnclient.txt
5350 INFO: checking PYZ
5350 INFO: Building PYZ because out00-PYZ.toc is non existent
5350 INFO: Building PYZ (ZlibArchive) D:\hj_workflow\cmdb\new_win_client\build\client\out00-PYZ.pyz
5572 INFO: checking PKG
5573 INFO: Building PKG because out00-PKG.toc is non existent
5573 INFO: Building PKG (CArchive) out00-PKG.pkg
5615 WARNING: One binary added with two internal names. C:\WINDOWS\SYSTEM32\pywintypes34.dll was placed at .\pywintypes34.dll previously.
8499 INFO: Bootloader C:\Python34\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
8499 INFO: checking EXE
8499 INFO: Building EXE because out00-EXE.toc is non existent
8499 INFO: Building EXE from out00-EXE.toc
8500 INFO: Onefile Mode - Embedding Manifest into EXE file
8502 INFO: Updating manifest in C:\Users\User\AppData\Local\Temp\tmpemeovnuk
8503 INFO: Updating resource type 24 name 1 language 0
8511 INFO: Appending archive to EXE D:\hj_workflow\cmdb\new_win_client\dist\client.exe

D:\hj_workflow\cmdb\new_win_client>D:\hj_workflow\cmdb\new_win_client\dist\client.exe
WARNING: file already exists but should not: C:\Users\User\AppData\Local\Temp\_MEI135002\pywintypes34.dll
```

**Run error:**

```
D:\hj_workflow\cmdb\new_win_client\dist\client.exe
WARNING: file already exists but should not: C:\Users\User\AppData\Local\Temp\_MEI135002\pywintypes34.dll
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
    from OpenSSL import rand, crypto, SSL
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\rand.py", line 11, in <module>
    from OpenSSL._util import (
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\OpenSSL\_util.py", line 6, in <module>
    from cryptography.hazmat.bindings.openssl.binding import Binding
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 305, in load_module
    exec(bytecode, module.__dict__)
  File "C:\Python34\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 11, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
  File "C:\Python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 481, in load_module
    module = loader.load_module(fullname)
ImportError: No module named '_cffi_backend'
client returned -1
```

I've got this import error too. This is probably caused by changes in the `cryptography 1.0`:
https://github.com/pyca/cryptography/blob/master/CHANGELOG.rst:

> Switched to the new cffi set_source out-of-line API mode for compilation. This results in significantly faster imports and lowered memory consumption. Due to this change we no longer support PyPy releases older than 2.6 nor do we support any released version of PyPy3 (until a version supporting cffi 1.0 comes out).
- cryptography <1.0 contained filenames `_cffi_.pyd` but with 1.0 those file aren't there anymore
- This needs more investigation how it should be fixed.

@mo0feng As a workaround you could try to use 0.9 and try include 'osrandom.h` as data files.

Thank you! @matysek  
I try to use 0.9.

@matysek 
Thanks for your help , i was successful when i copy files by your guidance.

**copy osrandom_engine.h  to ...\dist\client\cryptography\hazmat\bindings\openssl\src\osrandom_engine.h**

I'm hitting this same issue and am getting `ImportError: No module named '_cffi_backend'` like @mo0feng.

@matysek Is the accepted workaround still to downgrade to cryptography 0.9? What needs to be figured out to get this working with cryptography >= 1.0?

Actually, I figured it out.

We need to add `_cffi_backend` as a hidden import [here](https://github.com/pyinstaller/pyinstaller/blob/e99e4833ffd22d26306581271deefa8eead87db8/PyInstaller/hooks/hook-cryptography.py#L22):

``` python
hiddenimports = collect_submodules('cryptography.hazmat.bindings.openssl') + ['_cffi_backend']
```

@matysek - If that seems reasonable to you, I can go ahead and open a PR.

Related background reading from the cffi docs: http://cffi.readthedocs.org/en/latest/cdef.html?highlight=_cffi_backend

Alternately, perhaps we should create a `hook-cffi.py` that includes this kind of information?

@nchammas We'd appreciate a pull-request.

But I'm unsure if `hook-ciff` would be the correct one: for two reasons:
1. If `ciff` is pure python (as the  quote below says, I dod not check it),`_cffi_backend` should be found and there should be no need fo a `hook-ciff`.
2. ciff-docs say: 
   
   > ... a regular program using CFFI out-of-line does not need to import the cffi pure Python package at all. (Internally it still needs _cffi_backend ...

Anything I missed?

I've asked the cffi folks for advice on how to handle this over here: https://bitbucket.org/cffi/cffi/issues/247/listing-hidden-imports-when-freezing-a


Resolving patch:
diff --git a/PyInstaller/hooks/hook-cryptography.py b/PyInstaller/hooks/hook-cryptography.py
--- a/PyInstaller/hooks/hook-cryptography.py
+++ b/PyInstaller/hooks/hook-cryptography.py
@@ -19,7 +19,7 @@
 from PyInstaller.utils.hooks import collect_submodules, get_module_file_attribute
 
 # Add the OpenSSL FFI binding modules as hidden imports
-hiddenimports = collect_submodules('cryptography.hazmat.bindings.openssl')
+hiddenimports = collect_submodules('cryptography.hazmat.bindings.openssl') + ['_cffi_backend']
 
 
 # Include the cffi extensions as binaries in a subfolder named like the package.


Test patch: