No Module name Crypto - python

I am trying to import Crypto in my python program but i got error.
i am working on windows. please help.
cmd
C:\Users\Raw.306498\Desktop>pip3 install --upgrade pycryptodome
Requirement already up-to-date: pycryptodome in c:\users\raw.306498\appdata\lo
cal\programs\python\python37\lib\site-packages (3.8.0)
C:\Users\Raw.306498\Desktop>python test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
from Crypto.Cipher import DES
ModuleNotFoundError: No module named 'Crypto'
C:\Users\Raw.306498\Desktop>
test.py
from Crypto.Util.asn1 import DerBitString
from binascii import hexlify, unhexlify
passw=b'21566572697461733131'
s = unhexlify(passw)
cred=str(s,'ascii')

solution to this problem for windows users is explained in the documentations here
and it says:
The root cause is that, in the past, you most likely have installed an unrelated but similarly named package called crypto, which happens to operate under the namespace crypto
Fix the problem with:
pip uninstall crypto
pip uninstall pycryptodome
pip install pycryptodome
more elaboration of the cause can be seen in this github issue
UPDATE:
If the solution quoted from documentation did not work you have to change the package folder name from crypto into Crypto.
to find where the package folder is located:
find out where your python executable is located by this command: where python.
Output should look like this:
C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\python.exe
Now change your directory in cmd to the folder containing python:
cd C:\Users\_YourUserName_\AppData\Local\Programs\Python\Python37-32\
run these:
cd ..
cd cd Lib\site-packages
open the explorer in this directory:
explorer .
In the opened explorer, you can see a folder named: crypto rename it to Crypto. (the second one starts with a capital C)

i solved this issue
actually a similar named file is already store in python library so first i delete it then install pycrypto using pip

Related

How can i install python modules that have spaces in between?

I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.

Biopython - very basic questions about how to install

I'm trying to install Biopython but I've had some trouble. I've looked for an answer on the README, PDF manual and in other people's questions but they focus on more advanced problems while I'm still stuck at level 0.
I am a complete n00b so please, bear with me.
I have downloaded python3 and installed it on my Mac.
python3 --version
Python 3.7.3
pip3 --version
pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
I have then gone and downloaded biopython-1.77.tar.gz and uncompressed on my desktop.
From the biopython-1.77 folder, I did
python3 setup.py build
which I think worked OK (things moved on the screen). It was followed by
sudo python3 setup.py install
Likewise, I think this too worked.
Now, to test if the installation worked and if I'm ready to use Biopython I tried
python3
[>>>import Bio
but I get the error:
/Users/user/Desktop/biopython-1.77/Bio/__init__.py:126: BiopythonWarning: You may be importing Biopython from inside the source tree. This is bad practice and might lead to downstream issues. In particular, you might encounter ImportErrors due to missing compiled C extensions. We recommend that you try running your code from outside the source tree. If you are outside the source tree then you have a setup.py file in an unexpected directory: /Users/user/Desktop/biopython-1.77
BiopythonWarning,
I then tried to do this from elsewhere and I changed directory to the Python3.8 folder and tried
python3
[>>> import Bio
but I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'Bio'
I've also tried to specify the path to Bio within biopython-1.77 but I get a SyntaxError: invalid syntax on the first "/" within the path.
Any help to install Biopython will be much appreciated.

ImportError in Python

I tried to execute a program using geonames_rdf, but I cant execute it by this error:
Traceback (most recent call last):
File "geo1.py", line 13, in <module>
import geonames.config.log
ImportError: No module named config.log
I read several posts abot ImportError and I check the path of the system and it is correct. I'm working in a VirtualBox with a fresh Ubuntu 16.04.
The imports of my program are:
import sys
import os
import os.path
import logging
import geonames.config.log
import geonames.compat
import geonames.adapters.search
I've also tried add this line:
sys.path.append('/usr/local/lib/python2.7/dist-packages/geonames/')
The command that I used to instal this package was
sudo pip install geonames_rdf
Try appending site-packages not dist-packages. A bit of searching it looks like dist-packages is debian specific.
sys.path.append('/usr/local/lib/python2.7/site-packages/geonames/')
Reason:
Since you're installing 3rd party python package via pip it will not go into dist-packages and python rightfully cannot find it on the path.
Reference link:
What's the difference between dist-packages and site-packages?
I just tried to use geonames_rdf, but I didn't know I needed it to do a geonames search so I installed geonames first, then discovered I had to install fiona and gdal (I'm on Windows, had to install these two using prebuilt whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/). Don't know why these dependencies aren't baked into geonames.
Anyway once I then installed geonames_rdf it seemed to install into the geonames folder in c:\Python27\lib\site-packages, added at least the adapters package. In c:\Python27\lib\site-packages\geonames there is a config folder with log.py in it.

ImportError: No module named 'Crypto'

I am working with pycrypto. It works fine on my local windows machine, but when I move it to my python box I get an error with importing the module:
from Crypto.Cipher import ARC4
ImportError: No module named 'Crypto'
The output of python3.3 -c "from Crypto.Cipher import ARC4"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'Crypto'
output of pip3 list has a reference includes pycrypto (2.6.1)
I know it works with Python 2.7.6, but I wrote the script in 3.3 so it depends on some things from 3.3
As I already wrote in this answer:
WARNING: Don't use pycrypto anymore!
Use pycryptodome instead, via pip3 install pycryptodome.
But make sure that you don't have pycrypto installed, because both packages install under the same folder Crypto.
I am assuming that your "python box" is a remote computer.
First, make sure pycrypto is up to date (pip3 install --upgrade pycrypto). The older versions may not be compatible with python 3.3
If that doesn't work, try looking in site-packages (the directory) to make sure the functions actually exist.
If none of that works, it might be easier (just a suggestion) to use from future import the things you need. That way it is python 2&3 compatible.
Use pycryptodome, either install using pip or in case using IDE like pycharm install as a package via Preferences.
In case still gives error, use pycryptodomex (different from pycryptodome).
You will not see any error in importing from Cryptodome.Cipher import AES

installing paramiko on Windows

This may sound like a repeated question on SF, but I could not find a clear answer to it, yet.So.
I installed Paramiko 1.7 with "setup.py install" command and while running the demo.py program, I got this error:
Traceback (most recent call last):
File "C:\Documents and Settings\fixavier\Desktop\paramiko-1.7\demos\demo.py", line 33, in <module>
import paramiko
File "C:\Python26\lib\site-packages\paramiko\__init__.py", line 69, in <module>
from transport import randpool, SecurityOptions, Transport
File "C:\Python26\lib\site-packages\paramiko\transport.py", line 32, in <module>
from paramiko import util
File "C:\Python26\lib\site-packages\paramiko\util.py", line 31, in <module>
from paramiko.common import *
File "C:\Python26\lib\site-packages\paramiko\common.py", line 99, in <module>
from Crypto.Util.randpool import PersistentRandomPool, RandomPool
ImportError: No module named Crypto.Util.randpool
I'm getting this error even after installing PyCrypto 2.1.
On running test.py(which comes with the installation), I got the following error -
Traceback (most recent call last):
File "C:\Documents and Settings\fixavier\Desktop\pycrypto-2.0.1\pycrypto-2.0.1\test.py", line 18, in <module>
from Crypto.Util import test
File "C:\Documents and Settings\fixavier\Desktop\pycrypto-2.0.1\pycrypto-2.0.1\build/lib.win32-2.6\Crypto\Util\test.py", line 17, in <module>
import testdata
File "C:\Documents and Settings\fixavier\Desktop\pycrypto-2.0.1\pycrypto-2.0.1\test\testdata.py", line 450, in <module>
from Crypto.Cipher import AES
ImportError: cannot import name AES
I don't have the confidence to go ahead and install AES after all this, for all I know I may get another ImportError!
Please advice.Is it the way of installation thats problematic?
Looks like your pycrypto installation is broken or not installed.
Try to get a pycrypto for python2.6 installer here and try again after installing it.
http://www.voidspace.org.uk/python/modules.shtml#pycrypto
I tried Vijay's method,but it doesn't work.
I use the method on 'http://kmdarshan.com/blog/?p=3208',it works:
Goto to http://twistedmatrix.com/trac/wiki/Downloads and download the pycrypto package .exe for windows/python2.5. This is needed for running paramiko.
Next, download the paramiko package from http://www.lag.net/paramiko/.
Unzip paramiko to a temporary folder, better if you unzip it to the folder where python is installed.
Go into the folder for paramiko.
Open command prompt and see to it that you have python set as the environment variable.
Run this command python setup.py install
You will get a series of lines of compilation. Just make sure you dont have any error in them. If you have any errors you will need to re compile them again.
Just be be sure everything is alright import paramiko in your program and see.
FYI: paramiko is used for ssh..and so on.
Download paramiko for windows. You get the zip file:
www.lag.net/paramiko/
To build it you need the dependency package pycrypto. Again keep in mind you will need a matching version of pycrypto for your Python. This is a built version of Windows so no install is required. http://www.voidspace.org.uk/python/modules.shtml#pycrypto
You could do an easy_install by downloading setuptools but I ran into some issues so I chose to download MinGW tool. This is again an installation and no build is required. http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/mingw-get-inst/mingw-get-inst-20110316/
Once you have pycrypto and MinGW installed on your windows machine, just browse to the folder where you extracted the paramiko module from the zip file and issue this command:
python setup.py build --compiler=mingw32 bdist_wininst
TADA! You are all set to use ssh on your windows machine with Python.
I have installed paramiko onto 64bit Windows 7 successfully:
Install Python2.7
Download 64bit PyCrypto installation package from: http://www.dragffy.com/posts/ython-pycrypto-2-4-1-32-and-64-bit-windows-32x64-amdintel-installers
Download paramiko package from: http://www.lag.net/paramiko/
extract paramiko package
start a command line terminal from the extracted paramiko package, run
"python setup.py install"
I wanted to install Paramiko for Python 3.3.2 on Windows XP. I followed the instructions here
After I downloaded all programs on the list for my Python version, Paramiko starts without problems.
Install python-2.7.3.amd64.msi
Install pycrypto-2.6.win-amd64-py2.7.exe
Install setuptools-1.4.2.win-amd64-py2.7.exe
Install pip-1.4.1.win-amd64-py2.7.exe
Download and extract https://github.com/paramiko/paramiko/archive/master.zip
The actual problem does not seem to be a broken Crypto install but a slightly different one. After installing paramiko and crypto with easy_install on windows I do have crypto installed but not Crypto. I installed the package PyCrypt (which gave an error because I didn't have a C compiler before I installed visual studio express)
It appears that the Crypto package you downloaded doesn't have AES...
you should try doing the following:
import Crypto
import Crypto.Util
import Crypto.Cipher
if any of those fail then you still need to make sure pycrypto is installed (see the link from S.Mark here), otherwise Paramiko might not depend on having AES (even though there is a test for that)
It seems PyCrypto uses a c-compiler(which is inherently present on the Linux system - gcc).
Also, somewhere on the PyCrypto readme.txt file says, it needs to be 'build' first, before doing an 'install'
On Linux, I build it first and then ran 'install' command on it and was successfully installed.
I searched for a long time looking for a solution to this problem. I'm running Windows 7 64-bit and python 2.7. None of the above solutions worked for me.
this one did
Don't forget to include the C++ compiler when you download the Microsoft SDK, it wasn't checked by default.
I downloaded the pycrypto 2.5 source to do the compile and the paramiko 2.3, things work well.
Here is a very precise answer:
Step 1: Go to https://github.com/paramiko/paramiko
Step 2: Download the zip file, and extract it
Step 3: Move into the folder and run python setup.py install
You are done!
I had the similar problem on my mac and the way I solved it was by simply just renaming the "crypto" directory to the "Crypto". I already had the paramiko and ssh installed in it. They both work perfectly fine now. However, this may or may not work for some one but this is just a simple thought on getting the ways around this problem.
just try
pip install paramiko
if this shows error, then
pip install cryptography
pip install paramiko

Categories

Resources