cx_freeze comaptibility
Issue:
cxfreeze fail including the openssl dllin the build
- Work without cx_freeze
- cx_freeze perfectly without cryptography
Error message
cffi/ffiplateform,py ligne48 in _build distutils.errors.DistutilsModuleError invalid command build
Remarks
Maybe I miss some include, in setup.py but if not what can bee done to force cryptography beeing exported corectly by cx_freeze
cc: @dstufft :-)
"K:\foo.exe"
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "K:\foo.py", line 25, in <module>
import gui.main
File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
File "K:\foo\gui\main.py", line 1, in <module>
from cryptography.fernet import Fernet
File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\cryptography\fernet.py", line 26, in <module>
from cryptography.hazmat.primitives import hashes, padding
File "X:\Python34\lib\importlib\_bootstrap.py", line 2284, in _handle_fromlist
File "X:\Python34\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed
File "X:\Python34\lib\importlib\_bootstrap.py", line 2237, in _find_and_load
File "X:\Python34\lib\importlib\_bootstrap.py", line 2226, in _find_and_load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "X:\Python34\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\cryptography\hazmat\primitives\padding.py", line 75, in <module>
ext_package="cryptography",
File "C:\Python34\lib\site-packages\cffi\api.py", line 340, in verify
lib = self.verifier.load_library()
File "C:\Python34\lib\site-packages\cffi\verifier.py", line 74, in load_library
self._compile_module()
File "C:\Python34\lib\site-packages\cffi\verifier.py", line 139, in _compile_module
outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
File "C:\Python34\lib\site-packages\cffi\ffiplatform.py", line 25, in compile
outputfilename = _build(tmpdir, ext)
File "C:\Python34\lib\site-packages\cffi\ffiplatform.py", line 48, in _build
dist.run_command('build_ext')
File "C:\Python34\lib\distutils\dist.py", line 972, in run_command
cmd_obj = self.get_command_obj(command)
File "C:\Python34\lib\distutils\dist.py", line 846, in get_command_obj
klass = self.get_command_class(command)
File "C:\Python34\lib\distutils\dist.py", line 832, in get_command_class
raise DistutilsModuleError("invalid command '%s'" % command)
distutils.errors.DistutilsModuleError: invalid command 'build_ext'
hope it may help
cc: @glyph
Currently my assumption is that K:\Foo.exe built without errors from cx_Freeze, but then has this traceback when run.
It would be nice to have a link to the particular project being built here, but I assume I'm going to have to do quite a bit of experimenting to get it to work anyway, so I'll report my own findings :-).
@tychotatitscheff - it might save me some time if you could explain - what version of visual studio are you using, what version of Python, did you download it or build it yourself, etc?
@glyph - sorry for the short explanation. I maid just in job just before going back home.
Plateform
- Windows 7 (64 bits)
- python 3.4 (64 bits)
- https://github.com/pyca/cryptography installed from wheel (so no openssl installed nor visualstudio)
Project
I would like to provide the project but its actually a project from some big firm, including confidential data. I will try to simplify the project on monday and provide small code to reproduce the issue.
To be simple its a pyqt project with Qettings encrypted on fly by cryptography (keys made by derivation fonction from a sha 256 of the password)
It compiles without issue but the crash on load.
@tychotatitscheff Try including distutils in setup.py packages.
According to cx_freeze mailing list http://sourceforge.net/p/cx-freeze/mailman/message/32693004/
This might have been improved by #1467. I'm not sure though.
This is in theory improved by the removal of implicit compile. We don't have the info to further investigate, so I'm going to close this issue; if you can still reproduce, leave a comment and we'll reopen.
I have the same problem, added distutils and cryptography to the packages but no luck.
Here is my setup (on WinXP):
- python 2.7.6
- cx-freeze 4.3.3
- cryptography 0.6.1
- pyOpenSSL 0.14
- cx_freeze setup file: http://pastebin.com/kYi5FLzn
If you can please try with the current master branch as it has significant changes to our compilation methodology.
I did compile sources from master with OpenSSL 1.0.1j. The program was throwing implicit compile error, then I reinstalled cffi and other dependencies but finally I got the same error :(
Maybe I have to write to the cx_freeze mailing list.
With both versions (4.3.3 and master) the compiled cryptography._Cryptography_xxxxx.pyd files get into the root of the package but when I launch it tries to build the module again. I don't get why it throws the exception if the package has all its dependencies just there.
I can dig into the code if necessary, just give me some clue. Thank you very much
After a few days fighting this problem on and off, I started adding print statements all along the call chain, including Verifier.py in the site-packages directory. I found that it is looking for the _cryptography*pyd files in the pycache under my python home directory.
Long story short, this hack made it work:
In src\cryptography\hazmat\bindings\utils.py around line 112 is def build_ffi(...):, and: tmpdir='', I changed that to: tmpdir=os.path.dirname(os.path.realpath(sys.argv[0])), Rebuild and reinstall cryptography package. Then after the cx_freeze I did: ren "cryptography._Cryptography_cffi_3a414503xe735153f.pyd" "_Cryptography_cffi_3a414503xe735153f.pyd" ren "cryptography._Cryptography_cffi_590da19fxffc7b1ce.pyd" "_Cryptography_cffi_590da19fxffc7b1ce.pyd" ren "cryptography._Cryptography_cffi_8f86901cxc1767c5a.pyd" "_Cryptography_cffi_8f86901cxc1767c5a.pyd" and now my program works without an interpreter - whew!
It darn works! Thank you very much Mike
@dstufft I realize this is somewhat outside your wheelhouse but is there a sane way we can support this use case without users needing to modify the released version? What's cffi doing here?
So the hashes aren't changing, that's good it means that it's looking for the right file, it's just doing it in the wrong place.
Changing the tmpdir is probably doing something where it enables cffi to write out the .c file. You probably don't need that change if you rename the .pyd files first. My guess is that something that cx_freeze does is making it so import cryptography; cryptography.__path__ is None. See here: https://bitbucket.org/cffi/cffi/src/67435ba27473de84824708c1f222bb915ddb1e03/cffi/verifier.py?at=default#cl-136 that would cause it to act as if there wasn't an ext_package defined.