17

I'm trying my hands on encryption for a while now. I recently got hands on this python based crypter named PythonCrypter.

I'm fairly new to Python and when I try to open the CodeSection.py file via terminal, I get error saying from Crypto.Cipher import AES ImportError: No Module Named Crypto.Cipher

What am I doing wrong?

Arion_Miles
  • 163
  • 1
  • 2
  • 13
  • you need to install pycrypto – Joran Beasley Jul 17 '15 at 21:41
  • 2
    Unfortunately that doesn't seem like a well-managed project - there's no `requirements.txt` or `setup.py` to let you easily install it and its dependencies. You will need to identify any third-party packages it depends on yourself, and install them manually. Searching for `Crypto.Cipher` leads you to [`pycrypto`](https://pypi.python.org/pypi/pycrypto), for example. – jonrsharpe Jul 17 '15 at 21:42
  • Was a solution ever found for this issue? I'm having the same problem on Ubuntu 17 – yalpsid eman May 24 '17 at 00:52

9 Answers9

50
pip uninstall Crypto
pip uninstall pycrypto
pip install pycrypto

That works for me.

The point is, when you install pycrypto, you should remove Crypto first

bin456789
  • 672
  • 6
  • 12
15

I just encountered this issue with Python 2.7 on Windows. My solution was to rename the folder from ..\site-packages\crypto to ..\site-packages\Crypto. The lower case "c" was causing the import error.

See https://github.com/pypa/pip/issues/3309 for details.

thephez
  • 362
  • 4
  • 12
8

In order to use the pycypto library you should install it with:

pip install pycrypto

or

easy_install pycrypto
omri_saadon
  • 10,193
  • 7
  • 33
  • 58
  • @KanishkSingh try to download the tar file and install it. https://pypi.python.org/pypi/pycrypto – omri_saadon Jul 17 '15 at 22:37
  • @Arion_Miles It's seems to be a problem with vcvarsall.bat, you need to install visual studio c++, for more info click the link http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat – omri_saadon Jul 17 '15 at 23:22
  • Yes, I installed the C++ compiler mentioned and pycrypto install all perfectly, but this program still has trouble importing crypto.cipher I believe it's because my Pycrypto is stored within 'C:\Python27\Lib\site-packages' and this program might be trying to fetch it from 'C:\Python27\Scripts' – Arion_Miles Jul 18 '15 at 08:15
  • have you tried to copy the files there? @Arion_Miles – omri_saadon Jul 18 '15 at 09:24
3

PyCrypto doesn't play well with Windows systems if you're installing using pip or easy_install... or at least it didn't for me.

Try using the prebuilt binaries for Windows here: http://www.voidspace.org.uk/python/modules.shtml#pycrypto

johnny_be
  • 299
  • 1
  • 2
  • 11
  • Tried what you suggested. Installed "PyCrypto 2.6 for Python 2.7 32bit" It installed correctly but I'm still getting the same error. – Arion_Miles Jul 18 '15 at 08:24
  • 1
    @Arion_Miles Is it possible that you have two separate versions of Python installed on your machine has two versions of Python installed? Also, looking at the comments above, if Pycrypto is in 'C:\Python27\Lib\site-packages' (which is where it should be), you should make sure that is included in your PATH variable within Environment Variables. – johnny_be Jul 20 '15 at 16:33
  • 1
    Do I need to specifically add "C:\Python27\Lib\site-packages" in my environment variables path? If not, then what do I need to add? – Arion_Miles Jul 20 '15 at 17:03
  • 1
    @Arion_Miles Usually when you install Python, it adds it the the environment variables path for you, but if it's not there, then yes, specifically add "C:\Python27\Lib\site-packages" – johnny_be Jul 20 '15 at 17:33
  • Btw, for more information on how Python interacts with the system path as defined in environment variables, check out this [link](http://www.diveintopython3.net/your-first-python-program.html#importsearchpath) – johnny_be Jul 20 '15 at 17:36
2

I just spent half an hour figuring this out on Ubuntu. Turns out, I had installed the python-pycryptopp package through apt (I prefer to avoid pip if possible), but the package I needed was actually python-crypto.

2

In ubuntu 18.04.2 LTS installing pycryptodome package resolved the issue

deepak
  • 21
  • 2
1

In my case, pycrypto package was not installed, when I tried to add it: I ran into the following error which was rectified by downloading and installing C++ Compiler for Python 2.7.

error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27

Amin
  • 11
  • 1
0

I think u should try this:

sudo pip2 install pycrypto
Mr. T
  • 11,960
  • 10
  • 32
  • 54
pri
  • 104
  • 1
  • 8
0

I know this has already been answered, but I want to expand a little bit

pip install Crypto --> IS THE WRONG PACKAGE

if you do this run the below to remove it:

$> pip uninstall Crypto

Now, to install type:

$> pip uninstall pycrypto --> just in case you have a broken package already

$> pip install pycrypto

On macOS Catalina this will automatically install the pycrypto package for Python3.6 ONLY.

This means that if you run:

python your_script.py

It wil fail. Unless of course Python3 is set as your default.

Now if you really want to run pycrypto on Python2 you can run the below

$> sudo pip2 install pycrypto

You will need the sudo for this to work!

This will install pycrypto for Python2 only.

I hope this helps someone who might be installing then running with python2, or who wants the package installed with Python2 but is continuously installing with the Python3 package

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100