3

I'm using the pycrypto module to encrypt files. When running the python code, it works well:

$ python encrypt_file.py file

but when I build encrypt_file.py to a binary:

$ pyinstaller -F zip_disk.py

and run the binary under dist

$ ./encrypt_file file

it shows the following error:

File "<string>", line 24, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/xxxx/zip_disk/build/zip_disk/out00-PYZ.pyz/Crypto.Cipher.AES", line 50, in <module>
ImportError: cannot import name _AES

Why does this happen?
How to fix ImportError?

  • My import statement is
    from Crypto.Cipher import AES
    
  • Python version: Python 2.7.6
  • PyCrypto version is 2.6.1. I have tried to install pycrypto from source and via pip, both result in the the same ImportError.
  • Platform: Linux Ubuntu 3.13.0-32-generic x86_64 x86_64 GNU/Linux
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
coanor
  • 3,746
  • 4
  • 50
  • 67
  • Most likely extensions are not built (or if built) are not in correct path for you. – gabhijit Jun 30 '15 at 09:38
  • @gabhijit: I have tried install `pycrypto` from source and via `pip`, both the same `ImportError` – coanor Jun 30 '15 at 09:42
  • 1
    Maybe you could refer to [Python AES import error Please](http://stackoverflow.com/questions/26943136/python-aes-import-error-please) – Eric Tsui Jun 30 '15 at 11:03

1 Answers1

1

The pycrypto developers have stopped futher upgrades. Use instead pycryptodome which replaces pycrypto.

pip install pycryptodome

Now it works fine (did for me)!

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34