![]() |
|
[Python] Python import error - module not found - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Python import error - module not found (/showthread.php?tid=5976986) |
Python import error - module not found - Magpi3 - Jun 5, 2019 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 pythonThis 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 RE: Python import error - module not found - Cash - Jun 5, 2019 Are you sure you’re on Python 3.x.x? Assuming you are, try this inside terminal: Code pip uninstall scapyRE: Python import error - module not found - Magpi3 - Jun 5, 2019 (Jun 5, 2019 12:33 PM)Cash Wrote: Are you sure you’re on Python 3.x.x? 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. RE: Python import error - module not found - Deathbox - Jun 5, 2019 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. RE: Python import error - module not found - Magpi3 - Jun 5, 2019 (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 RE: Python import error - module not found - Deathbox - Jun 5, 2019 (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 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 pythonPick the number corresponding to python 3.x version RE: Python import error - module not found - Magpi3 - Jun 6, 2019 (Jun 5, 2019 05:19 PM)Deathbox Wrote: I use geany with the dark theme: 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 RE: Python import error - module not found - Deathbox - Jun 6, 2019 Magpi3 Wrote:Oh my god, yeah I see it now, I just had to double click on pip and search for the right module, 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. |