Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Python import error - module not found

This error has cursed me for a long time and despite how much research I havent found a solution to it.

Code
#!/usr/bin/env python


import scapy

def scan(ip):
   scapy.arping(ip)

scan("10.10.10.10")

This is my code and despite this, whenever it is ran I get the following error:
ModuleNotFoundError: No module named 'scapy'

This has happened for other modules as well as this whole error made me take a long break from python because I had no solution.

I have already tried pip install but nonetheless the module has already been installed and so I am hit with Requirement already satisfied: pathname

I have tried numerous other things but none have worked and I am truly stumped.
Please if there is a way of fixing this let me know, as I am new to python, please also make it understandable, thank you

having this fixed will be an enourmous help
Are you sure you’re on Python 3.x.x?

Assuming you are, try this inside terminal:

Code
pip uninstall scapy

pip install scapy
(Jun 5, 2019 12:33 PM)Cash Wrote:  Are you sure you’re on Python 3.x.x?

Assuming you are, try this inside terminal:

Code
pip uninstall scapy

pip install scapy

Yeah, as far as I know im using the latest PyCharm and the following happens when i enter those commands:

@KALI:~$ pip install scapy
Requirement already satisfied: scapy in /usr/lib/python2.7/dist-packages (2.4.0)
@KALI:~$ pip uninstall scapy
Not uninstalling scapy at /usr/lib/python2.7/dist-packages, outside environment /usr
Can't uninstall 'scapy'. No files were found to uninstall.

I then try pip3 and this happens:

magpi3@KALI:~$ pip3 install scapy --no-cache-dir
Collecting scapy
 Downloading files.pythonhosted.org/packages/d0/04/b8512e5126a1816581767bf95cbf525e0681a22c055bcd45f47ecff60170/scapy-2.4.2.tar.gz (795kB)
   100% |████████████████████████████████| 798kB 9.5MB/s
Installing collected packages: scapy
 Running setup.py install for scapy ... done
Successfully installed scapy-2.4.2

But when the error still remains - Module not found, im confused around this.
I don't use PyCharms, as I prefer Geany but I was told you have to load each module you install in PyCharms itself in order for it to work. When I get this error, I install the package from my debian repos (take python3-tk for example) and then it is resolved. If it isn't, I use pip to install it and then the error goes. I tend to do both out of habit. Run your python code from the command line, not inside PyCharm and see if you get the same error.
Pink Floyd is one of my many addictions. I'm sorry but I'm a free member and thus, I cannot give rep back to you kind folk who have blessed me with your presence.

My howto on Arch servers on ARM devices (samba/dynamicdns/staticip/vncserver/ssh)
https://goo.gl/DgMvRt
(Jun 5, 2019 12:59 PM)Deathbox Wrote:  I don't use PyCharms, as I prefer Geany but I was told you have to load each module you install in PyCharms itself in order for it to work. When I get this error, I install the package from my debian repos (take python3-tk for example) and then it is resolved. If it isn't, I use pip to install it and then the error goes. I tend to do both out of habit. Run your python code from the command line, not inside PyCharm and see if you get the same error.

Ok so following your advice the module error was gone but I was hit with minor syntax errors:

Traceback (most recent call last):
File "Network-Scanner.py", line 9, in <module>
scan("")
File "Network-Scanner.py", line 7, in scan
scapy.arping(ip)
AttributeError: 'module' object has no attribute 'arping'


Even so is there no way for this to work with PyCharm?, Im not gunna run it through console every time I want to test a script
if no, is there another IDE like the one you mentioned that may prevent this error from happening?

I tried using the default python program on windows a while back and had the same error with a different module
Lemme know what you think

ALSO SIDE NOTE - im on python 3.7
(Jun 5, 2019 01:23 PM)Magpi3 Wrote:  Even so is there no way for this to work with PyCharm?, Im not gunna run it through console every time I want to test a script
if no, is there another IDE like the one you mentioned that may prevent this error from happening?

I tried using the default python program on windows a while back and had the same error with a different module
Lemme know what you think

ALSO SIDE NOTE - im on python 3.7

I use geany with the dark theme:

Spoiler (Click to View)

Geany build settings (hit F5 to execute and run):

Spoiler (Click to View)

Try changing your import line to:

Code
from scapy.all import *

As for pycharm:
File --> Project Interpreter  --> Double click on pip package  --> Search for module name  --> Install modulename


I'm also using Python 3.7 on Debian testing. I just edit the build properties and edit the python path to say python3 instead of python so it has build paths to python 3. We should all be moving away from python 2.7 now. Let me know if this works :).

Set Python 3 as default for the system if you're on Linux:

Code
update-alternatives --config python

Pick the number corresponding to python 3.x version
Pink Floyd is one of my many addictions. I'm sorry but I'm a free member and thus, I cannot give rep back to you kind folk who have blessed me with your presence.

My howto on Arch servers on ARM devices (samba/dynamicdns/staticip/vncserver/ssh)
https://goo.gl/DgMvRt
(Jun 5, 2019 05:19 PM)Deathbox Wrote:  I use geany with the dark theme:

[spoiler]
[img]

Geany build settings (hit F5 to execute and run):

[spoiler]
[img]

Try changing your import line to:

Code
from scapy.all import *

As for pycharm:
File --> Project Interpreter  --> Double click on pip package  --> Search for module name  --> Install modulename


I'm also using Python 3.7 on Debian testing. I just edit the build properties and edit the python path to say python3 instead of python so it has build paths to python 3. We should all be moving away from python 2.7 now. Let me know if this works :).

Set Python 3 as default for the system if you're on Linux:

Code
update-alternatives --config python

Pick the number corresponding to python 3.x version




Oh my god, yeah I see it now, I just had to double click on pip and search for the right module,
thanks man, you've been a huge help
Magpi3 Wrote:Oh my god, yeah I see it now, I just had to double click on pip and search for the right module,
thanks man, you've been a huge help

You're very welcome! Some modules namely Kivy on python 3.7 like to work better in virtual environments. So if you get a similar error in future and it's installed via PIP, distribution repo and in PyCharm then it's likely that you need to install all the modules you need into a virtual env instead. If this makes no sense don't worry, it's only specific modules and kivy is the only one I've run into this problem with, it isn't a problem on previous python 3.x versions.
Pink Floyd is one of my many addictions. I'm sorry but I'm a free member and thus, I cannot give rep back to you kind folk who have blessed me with your presence.

My howto on Arch servers on ARM devices (samba/dynamicdns/staticip/vncserver/ssh)
https://goo.gl/DgMvRt


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 238 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad
[Shell] by Emre_May 27, 2020 04:36 AM 0 105 May 27, 2020 04:36 AM
Last Post: Emre_