impacket module not found but installed

Hey guys, I hope you can help me.
I’m trying to execute a python script and get following error:

$ python test.py
Traceback (most recent call last):
File “test.py”, line 11, in <module
from impacket import smb
ImportError: No module named impacket

The impacket module is installed as you can see:

$ pip show impacket
Name: impacket
Version: 0.9.23.dev1+20201209.133255.ac307704
Summary: Network protocols Constructors and Dissectors
Home-page: Impacket – SecureAuth
Author: SecureAuth Corporation
Author-email: oss@secureauth.com
License: Apache modified
Location: /usr/local/lib/python3.9/dist-packages
Requires: ldapdomaindump, pycryptodomex, pyasn1, six, ldap3, pyOpenSSL, flask
Required-by:

Content of my test file:

cat test.py
#!/usr/bin/python

import struct
import time
import sys

from threading import Thread #Thread is imported incase you would like to modify

from impacket import smb
from impacket import uuid
from impacket import dcerpc
from impacket.dcerpc.v5 import transport

print(‘works’)

I already uninstalled impacket via pip and also get impacket from git and install it from there. But still no luck.

Hard to be sure but the likely issue is you have Impacket installed in a different version of python than your script is calling.

Type your comment> @TazWake said:

Hard to be sure but the likely issue is you have Impacket installed in a different version of python than your script is calling.

Hey TazWake, thx for you response.
Well, I’ve copied just the import section from the following script (searched via searchsploit) to test why it does not work exactly:

Microsoft Windows - ‘NetAPI32.dll’ Code Execution (Python) (MS08-067) | windows/remote/40279.py

Any ideas how to be sure if maybe the version of impacket is wrong.

You could try python --version to see what the default runs as. If you have it installed in python3 you may need to specify that on the command line, or with python2 if you have it that way round.

I’ve no idea about the version of impacket.

Finannly found a solution, after hours of googling.

See here: https://twitter.com/pry0cc/status/1323294727261868032

Long story short:
pip uninstall impacket

Install pip2:
curl bootstrap.pypa.io/get-pip.py -o get-pip.py; python2 get-pip.py
python2 get-pip.py

Then pip2 install impacket

Yeah python is being bonkers over the last new updates.
Lots of stuff broken. You just have to find a way to install the missing packages in a lot of them but python2 -m pip or python3 -m pip is your friend.

Tenia problemas para instalar la libreria imapcket para python2.7
no podia usar pip2 porque no estaba instalado
para instalar pip2 correctamente sigue las intruscciones aqui:

despues
pip2 install impacket

got the the same issue and olny resolved from the blow post after two days

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py

#sudo python2.7 get-pip.py
#pip2.7 install --upgrade setuptools
#python2.7 -m pip install impacket