jasonacox/tuyapower

No module named 'Crypto'

moji2002 opened this issue · 11 comments

i got this error

python -m tuyapower
Traceback (most recent call last):
File "C:\Python38\lib\runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Python38\lib\runpy.py", line 144, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "C:\Python38\lib\runpy.py", line 111, in get_module_details
import(pkg_name)
File "D:\Programing\tuya\tuyapower\tuyapower_init
.py", line 40, in
from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

You are missing the Crypto module. You will need to install it:

python -m pip install pycryptodome

I'm closing this issue since I haven't heard back. However, please feel free to re-open it if that does not fix your problem:

python -m pip install pycryptodome

Just to point this out. I'm having the exact same issue. Here's a list of installed packages and me running the commands setup.py, scan.py and test.py.

WARNING: Could not generate requirement for distribution -rypto 1.4.1 (c:\python39\lib\site-packages): Parse error at "'-rypto=='": Expected W:(abcd...)
WARNING: Could not generate requirement for distribution -ip 20.2.3 (c:\python39\lib\site-packages): Parse error at "'-ip==20.'": Expected W:(abcd...)
pyaes==1.6.1
pycryptodome==3.9.9
tinytuya==1.0.4
tuyapower==0.0.25

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>setup.py
Traceback (most recent call last):
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\setup.py", line 3, in <module>
    from tuyapower import __version__
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\tuyapower\__init__.py", line 42, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>scan.py
Traceback (most recent call last):
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\scan.py", line 16, in <module>
    from Crypto.Cipher import AES  # PyCrypto
ImportError: No module named Crypto.Cipher

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>test.py
Traceback (most recent call last):
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\test.py", line 12, in <module>
    import tuyapower
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\tuyapower\__init__.py", line 42, in <module>
    from Crypto.Cipher import AES
ImportError: No module named Crypto.Cipher

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>```

I see that you are running python 3.9 on Windows. Full disclosure, I rarely use windows so there may be a better fix, but in my experience, Windows Python modules get corrupt or mapped wrong. My fix is to always uninstall and reinstall the packages:

C:\Users\jason> pip uninstall pycryptodome
C:\Users\jason> pip uninstall crypto
C:\Users\jason> pip uninstall tuyapower

C:\Users\jason> pip install pycryptodome
C:\Users\jason> pip install tuyapower

C:\Users\jason> python -m tuyapower

Thanks for the tip, but I was already a step ahead of you as I had done a reinstall of all of the related modules. Even deleted the pip cache.

It also seems that my initial copy paste of the console output did not include the pip freeze command which lists all installed packages.

Which versions of python do you have installed? (note: py is a command installed on Window via the python installer)

py -0

My default was set to python 3.7. When I switched to 3.9 the modules were corrupt and I had to reinstall them.

py -m pip uninstall pycryptodome
py -m pip install pycryptodome

Also, make sure you do not have pycrypto installed. It doesn't work well on Windows. This should show the modules you have installed:

py -m piip list

Do you get the same errors with py -m tuyapower ?

Ran all of these in the same command promt. I have a feeling I might simply need to add additional modules to my PATH or something?

Which versions of python do you have installed? (note: py is a command installed on Window via the python installer)

Installed Pythons found by py Launcher for Windows
 -3.9-64 *
 -3.8-64
 -2.7-64

My default was set to python 3.7. When I switched to 3.9 the modules were corrupt and I had to reinstall them.

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>py -m pip uninstall pycryptodome
Found existing installation: pycryptodome 3.9.9
Uninstalling pycryptodome-3.9.9:
  Would remove:
    c:\python39\lib\site-packages\crypto\*
    c:\python39\lib\site-packages\pycryptodome-3.9.9.dist-info\*
  Would not remove (might be manually added):
    c:\python39\lib\site-packages\crypto\~ibrary\__init__.py
    c:\python39\lib\site-packages\crypto\~ibrary\cryptor.py
    c:\python39\lib\site-packages\crypto\~ibrary\hash.py
    c:\python39\lib\site-packages\crypto\~ibrary\package.py
Proceed (y/n)? y
  Successfully uninstalled pycryptodome-3.9.9

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>py -m pip install pycryptodome
Collecting pycryptodome
  Using cached pycryptodome-3.9.9-cp39-cp39-win_amd64.whl (14.1 MB)
Installing collected packages: pycryptodome
Successfully installed pycryptodome-3.9.9

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>py -m pip list
Package      Version
------------ -------
-ip          20.2.3
-rypto       1.4.1
pip          20.2.4
pyaes        1.6.1
pycryptodome 3.9.9
setuptools   50.3.2
tinytuya     1.0.4
tuyapower    0.0.25
wheel        0.35.1

Also, make sure you do not have pycrypto installed. It doesn't work well on Windows. This should show the modules you have installed:

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>py -m pip list
Package      Version
------------ -------
-ip          20.2.3
-rypto       1.4.1
pip          20.2.4
pyaes        1.6.1
pycryptodome 3.9.9
setuptools   50.3.2
tinytuya     1.0.4
tuyapower    0.0.25
wheel        0.35.1

Do you get the same errors with py -m tuyapower ?

C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25>py -m tuyapower
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Python39\lib\runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Python39\lib\runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "C:\Users\Feiko\Downloads\tuyapower-0.0.25\tuyapower-0.0.25\tuyapower\__init__.py", line 42, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'

I managed to resolve the issue by renaming the crypto folder in python install/Lib/site-packages from crypto to Crypto!

That's great!

It may not matter since you hacked it to work, but looking at the pip list you send the first two modules are corrupt and should not be there. I suspect this could be causing some of the problem as well - it looks like the first was supposed to be "pip" and second one "Crypto" but they got renamed with a "-" prefix:

-ip          20.2.3
-rypto       1.4.1

Yeah that could very well be the case. although the Crypto rename issue seems to be something common as I've spotted it multiple times across the interwebs.