Python(3.6): program was not found in path - python-3.x

On Windows 10 (PyCharm IDE), i tried import the pythone-nmap module to get PortScenner.
The code i wrote:
import nmap
ns = nmap.PortScanner()
a = ns.nmap_version()
print(a)
Afterward, i got the following error:
C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\python.exe
C:/Users/Mind1/PycharmProjects/testNmap/main.py
Traceback (most recent call last):
File "C:/Users/Mind1/PycharmProjects/testNmap/main.py", line 2, in
ns = nmap.PortScanner()
File
"C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py",
line 131, in init
os.getenv('PATH')
nmap.nmap.PortScannerError: 'nmap program was not found in path.
PATH is : C:\Program Files (x86)\Common
Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py;C:\tizen-studio\tools\ide\bin;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\;C:\Users\Mind1\AppData\Local\Microsoft\WindowsApps;C:\Program
Files\Microsoft VS
Code\bin;C:\Programing\SQLite3;C:\Users\Mind1\AppData\Local\Microsoft\WindowsApps;C:\Program
Files\JetBrains\PyCharm Community Edition
2019.2.3\bin;;C:\Users\Mind1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nmap\nmap.py;'
My questions are:
Why isn't it found in the path, when it is there at the end of the path?
Why are there 2 semi-colon before the last part of the path?
ps: I tried to add the path within the () of the PortScanner(), but that hasn't worked neither. (Not even when I used the double \ signs.

Related

Visual Studios - Nmap not found in Path, Creating Basic port scanner Python310

Firstly, I am following the tutorial at FreecodeCamp (https://www.freecodecamp.org/learn/information-security/python-for-penetration-testing/developing-an-nmap-scanner-part-1) - I may discontinue as there is so much ambiguity and little things wrong.. I honestly just want to follow a tutorial and have it work with what is done in the tutorial. X.X
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple Nmap automation tool.")
print("-----------------------------------------------")
ip_addr = input("Please Enter the IP you want to scan.")
print("The IP you entered is: ", ip_addr)
#Sanitize input
type(ip_addr)
c:\Users\WaffWaffles\Desktop\Python Projects>py scanner.py
Traceback (most recent call last):
File "c:\Users\WaffWaffles\Desktop\Python Projects\scanner.py", line 4, in
scanner = nmap.PortScanner()
File "C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\lib\site-packages\nmap\nmap.py", line 136, in init
raise PortScannerError(
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\metasploit-framework\bin\;C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\;"C:\Program Files (x86)\Nmap";C:\Users\WaffWaffles\AppData\Local\Programs\Microsoft VS Code\bin'
When I add
#!\C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310
to the top I get
c:\Users\WaffWaffles\Desktop\Python Projects>py scanner.py
Unable to create process using '\C:\Users\WaffWaffles\AppData\Local\Programs\Python\Python310\ scanner.py'
I have python-nmap installed through py -m install python-nmap too.

FileNotFoundError while using crontab to run Python script

I'm totally lost here. I'm trying to create a scheduler to run python script on my Mac, but I'm getting the following error:
Traceback (most recent call last):
File "/Users/Root/Desktop/Project/Data/script.py", line 148, in <module>
run(
File "/Users/Root/Desktop/Project/Data/script.py", line 121, in run
config = get_config("config")
File "/Users/Root/Desktop/Project/Data/config/__init__.py", line 3, in get_config
with open(f"config/{config_type}.json", "r") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'config/config.json'
So crontab convinces me that there is no such file or a directory, which is not true. I can run my script manually without errors.
My crontab is:
00 19 21 1-12 * /Library/Frameworks/Python.framework/Versions/3.9/bin/python3/ /Users/Root/Desktop/Project/Data/script.py >> /Users/Root/Desktop/Project/Data/cron.txt 2>&1
What am I doing wrong?
I'd be grateful for any help!
And is this possible without changing the relative path to an absolute path? I am aware of this solution
I assume crontab's cwd (Current Working Directory) is not same as where the script is stored.
this would solve your problem:
import os
script_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir(script_dir)
You can get the directory where you script is by calling "os.path.dirname(os.path.realpath(file))"
if you change the current working directory "os.chdir(...dir...)" you can access you config/config.json by relative path,
Otherwise you will have to use a absolute path
Try running this and check your output file:
import os
script_dir = os.path.dirname(os.path.realpath(__file__))
print (os.getcwd())
print(script_dir)
os.chdir(script_dir)
print (os.getcwd())
Try to open with full path to the json file.

Python: FileNotFoundError: [Errno 2] No such file or directory - How to add file to the right directory

I'm new to python! Seen many issues related to this problem but can't find the right way of doing it.
I want to import a picture and change it.
My code is:
from PIL import Image, ImageFilter
import os
root_dir= os.path.dirname(os.path.abspath(r'C:\Users\User\eclipse-workspace\Practice Python CS50 2019\images\Mario.png'))
before = Image.open('Mario.png')
after=before.filter(ImageFilter.BLUR)
after.save("MarioBLUR.png")
The error I'm getting is:
Traceback (most recent call last):
File "C:\Users\User\eclipse-workspace\Practice Python CS50 2019\src\Class 6\blur.py", line 5, in
before = Image.open('Mario.png')
File "C:\Users\User\anaconda3\lib\site-packages\PIL\Image.py", line 2809, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Mario.png'
My windows location for this picture is: C:\Users\User\Downloads\Mario.png
My eclipse location is: C:\Users\User\eclipse-workspace\Practice Python\images\Mario.png
How to add this picture to the right directory to make sure I won't have this issue anymore?
You only need the directory path and not the filename in os.path.dirname, for example:
root_dir= os.path.dirname('C:/Users/User/eclipse-workspace/Practice Python CS50 2019/images/')
before = Image.open(root_dir + 'Mario.png')
should work fine

Python in Visual Studio Code getting winError[5] Access denied from idescripts

it is my first time posting here so I apologize if this question is not correctly formatted.
I installed VSC to use it in developing STM32 code. I found the damongranlabs idescripts in github that would help greatly. While running the update.py script, I get the winError[5] access denied. VSC is using powershell as a terminal and I am running windows 10 with Python 3.8 32bit.
I have tried running VSC as an admin with no luck.
The following is what I get in powershell after attempting to run the script:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\Development\STM32\cubemxprojects\476EncTest> & d:/Development/STM32/cubemxprojects/476EncTest/ideScripts/update.py
Update started.
Existing '.vscode' folder used.
One STM32CubeMX file found: 476EncTest.ioc
Existing 'Makefile' file found (restored from '.backup').
Copy of file (new name: Makefile): D:/Development/STM32/cubemxprojects/476EncTest/Makefile.backup
Makefile 'print-variable' function added.
Valid 'buildData.json' file found.
Valid 'toolsPaths.json' file found.
'toolsPaths.json' file updated!
Enter path(s) to OpenOCD configuration file(s):
Example: 'target/stm32f0x.cfg'. Absolute or relative to OpenOCD /scripts/ folder.
If more than one file is needed, separate with comma.
Paste here and press Enter: C:\Users\omis2\AppData\Roaming\GNUMCUEclipse\GNU MCU Eclipse\OpenOCD\0.10.0-12-20190422-2015\scripts\target\stm32l4x.cfg
Enter path or command for 'stm32SvdPath':
Paste here and press Enter: C:\Users\omis2\AppData\Roaming\GNUMCUEclipse\Keil.STM32L4xx_DFP.2.2.0\CMSIS\SVD\STM32L4x6.svd
ERROR (55 seconds).
Unexpected error occured during 'Update' procedure. Exception:
Traceback (most recent call last):
File "D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\update.py", line 56, in <module>
makefileData = makefile.getMakefileData(makeExePath, gccExePath)
File "D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\updateMakefile.py", line 93, in getMakefileData
projectName = self.getMakefileVariable(makeExePath, gccExePath, self.mkfStr.projectName)[0]
File " D:\Development\STM32\cubemxprojects\476EncTest\ideScripts\updateMakefile.py", line 366, in getMakefileVariable
proc = Popen(arguments, stdout=PIPE)
File "C:\Users\omis2\AppData\Local\Programs\Python\Python38- 32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\omis2\AppData\Local\Programs\Python\Python38- 32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
Thanks for any help

Why does draw() in pygraphviz/agraph not work on the server (but locally)?

I have a Python app using Pygraphviz that works fine locally, but on the server the draw function throws an error. It happens in make_svg. The following lines are the relevant part of the errors I get. (The full trail is here.)
File "/path/to/app/utils/make_svg.py", line 17, in make_svg
prog='dot'
File "/path/to/pygraphviz/agraph.py", line 1477, in draw
fh = self._get_fh(path, 'w+b')
File "/path/to/pygraphviz/agraph.py", line 1506, in _get_fh
fh = open(path, mode=mode)
FileNotFoundError: [Errno 2] No such file or directory: 'app/svg_files/nope.svg'
Logging type(g) gives <class 'pygraphviz.agraph.AGraph'> as expected.
I work in a virtualenv in a mod_wsgi 4.6.5/Python3.7 environment on a Webfaction server.
Locally I use a virtualenv with Python 3.5.
The version of Pygraphviz is 1.3.1.(First I had 1.5 on the server. The error was exactly the same, except for the line numbers.)
What can I do?
The same error is described in this bug report from last year.
I don't get which directory I am supposed to create. svg_files exists and has rights 777.
The draw function at the end of make_svg should create the SVG.(And at the end of extract_coordinates_from_svg the file is removed again.)The file name is a hash created in connected_dag (svg_name).
On the server app/svg_files seems not to describe the same place as locally.
I defined the path unambiguously, and now it works.
file_path = '{grandparent}/svg_files/{name}.svg'.format(
grandparent=os.path.dirname(os.path.dirname(__file__)),
name=name
)
g.draw(file_path, prog='dot')

Resources