I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>
I have so far:
Updated to the current Python 3.10.7
Installed Nmap the first time from https://nmap.org/ for Windows
Uninstalled Nmap
Reinsalled Nmap using >>>pip3 install python-nmap
For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.
Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules - maybe PYTHONPATH-related), but the above can [usually] help.
It seems that Python cannot find nmap module.
You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables... and then edit PATH VARIABLE by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages
Related
I am using python3.
I installed twython on my MAC using pip3 command and I confirmed it was successfully installed.
When I run my python file, it comes up with:
ImportError : No module named twython
My code is as follows:
import sys
import string
import json as simplejson
from twython import Twython
I can't comment the response from #ajxs, but as additional information to his repsonse:
You can change the default python interpreter like this in your MAC terminal:
nano ~/.bash_profile
Add this to the file:
alias python=python3
exit the the bashrc file and run the following command:
source ~/.bash_profile
Now you can check the defaul python version with:
python --version
Maybe this helps you.
First thing that springs to mind is to check that you're running the script with the correct version of Python. Use python --version on the command line to check which version of Python you're executing by default. I've definitely had problems like this before when I've forgotten that my system's default version was 2.7 and I needed to use python3 to run Python 3 on the command line.
I have a simple script which is using signalr-client-py as an external module.
from requests import Session
from signalr import Connection
import threading
When I try to run my script using the sudo python myScriptName.py I get an error:
Traceback (most recent call last):
File "buttonEventDetectSample.py", line 3, in <module>
from signalrManager import *
File "/home/pi/Desktop/GitRepo/DiatAssign/Main/signalrManager.py", line 2, in <module>
from signalr import Connection
ImportError: No module named signalr
If I run my script typing only python myScriptName.py it works perfectly fine but I need to have the sudo in front because later on in my other scripts (that use this one) I perform write operation on the File system.
I am quite new to Python and that's why I need to know how I can handle this situation. If I type pydoc modules I get a list which contains:
signalr
signalrManager
If I type pip freeze I can see there listed:
signalr-client==0.0.7
By default sudo runs commands in different environment.
You can ask sudo to preserve environment with -E switch.
sudo -E python myScriptName.py
It comes with it's own security risks. So be careful
You need to check where signalr is installed. sudo runs the program in the environment available to root and if signalr is not installed globally it won't be picked up. Try 'sudo pip freeze' to see what is available in the root environment.
Another easy solution can be installing required packages via sudo -even they are installed before normally- instead of trying to match the paths:
sudo pip3 install <your-required-package-name>
After that you can execute the scripts via sudo.
I am using newest Kali and importing scapy ssl_tls package like this:
from scapy.layers.ssl_tls import *
But I get an error: WARNING: can't import layer ssl_tls: No module named ssl_tls
or
ImportError: No module named ssl_tls.
Also, to verify installation, I go into Scapy prompt and type TLS or SSL I get:
>>> TLS
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'TLS' is not defined
So it makes me believe that I didn't install it correctly. However I tried all 3 installation methods from official page and all worked without any errors.
I also have SSL installed: apt-get install libssl-dev
My system:
Linux kali 3.18.0-kali3-amd64 #1 SMP Debian 3.18.6-1~kali2 (2015-03-02) x86_64 GNU/Linux
Python2.7
Scapy version 2.2.1. Also tried 2.3.1.
scapy-ssl_tls version - current from https://github.com/tintinweb/scapy-ssl_tls
root#kali:~/Downloads# pip freeze | grep scapy
Warning: cannot find svn location for distribute==0.6.24dev-r0
scapy==2.2.0-dev
scapy-ssl-tls==1.2.1
NOTE: I have same exact python code running good on different Kali machine, on the same Python, Scapy and scapy-ssl_tls versions.
I just installed ssl_tls using pip. Using this installation method in my case config.py was not updated with added layer, which means that running scapy does not import ssl_tls automatically thus it is not possible to do from scapy.layers.ssl_tls import *. Your case sounds similar.
There are 2 options:
Update scapy's config.py (location depends on the way you installed scapy) by adding ssl_tls module. See https://github.com/tintinweb/scapy-ssl_tls#option-3-manual-installation for example
Import module using from scapy_ssl_tls.ssl_tls import * after importing scapy (or running scapy directly)
github/scapy-ssl_tls PR #55 fixes an issue where setup.py would not find all scapy installation dirs in case you have multiple locations for site-packages. Also see the updated installation instructions and troubleshooting. The fix is in master and will be in scapy-ssl_tls > 1.2.2. Please give it a try and raise a bug on github if this does not fix the issue for you. thanks
Please make sure your python version is > 2.7.6 and then run 'pip install scapy-ssl_tls'
I have an account in a CentOS server without sudo permission. As a result, I tried to install IPython from source code by python setup.py prefix=<my home directory>.
However, I got the Error:
Traceback (most recent call last):
File "/usr/bin/ipython", line 19, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
ImportError: No module named IPython.frontend.terminal.ipapp
I found a question same to mine: IPython import failure and python sys.path in general.
I followed the asker's instruction to add the directory of my IPython to the IPython execution file.
#!/usr/bin/python
"""Terminal-based IPython entry point.
"""
import sys
sys.path.append("./Ipython directory")
from IPython.frontend.terminal.ipapp import launch_new_instance
launch_new_instance()
However, I got the same error as well. So I want to know how can I launch IPython correctly? Thanks.
You probably want to install with the --user flag, which should put it on sys.path automatically.
python setup.py install --user
If you need to use --prefix for some other reason, then make sure that the directory you add to sys.path is the folder containing the IPython package, not the IPython directory. It will probably end with 'site-packages'.
I copied the IPython source folder into ~/bin/. The execution file of IPython can recognize the module in IPython and the IPython shell launches successfully.
I'm trying to use VirtualEnv for a Flask app that I'm creating since everyone has recommended me to do so. After creating my virtual environment, I installed the libraries that I needed using pip while the environment was activated. I'm running into ImportError problems with this script. The code works fine when I'm not in the virtual environment.
My script:
#!/usr/bin/python
import sc2reader
...
...
When I try to run it I get this:
(flaskapp)xxxx#xxxx-VirtualBox:~/flaskapp/bin$ ./test.py
Traceback (most recent call last):
File "./test.py", line 3, in <module>
import sc2reader
ImportError: No module named sc2reader
I've tried changing the shebang to reflect my VirtualEnv path for Python, but that didn't fix anything. The library is found in my site-packages folder in my virtual environment, so I'm not sure why I'm getting the ImportError.
I've never used VirtualEnv before so I'm assuming I configured it wrong so it's not seeing my site-packages.
Try using
#!/usr/bin/env python
as the shebang.
If that does not work, try seeing what is the output of which python.