deimos
deimos

Reputation: 21

module 'subprocess' has no attribute 'Popen' error, python

Can Someone Please Tell me what's wrong with my piece of code

#! /usr/bin/python3
import subprocess
import os

class NmapPy():
    def __init__(self, command=[]):
        self.command=command

    def scan(self):
        try:
            p=subprocess.Popen(self.command, shell=False,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out,err=p.communicate()
            print("\n Nmap scan is complete : ")
            print(str(out))
            print(str(err))
        except Exception as ex:
            print("Exception caught : "+str(ex))

nmap=NmapPy(["nmap", "-Pn", "-sV", "127.0.0.1"])
nmap.scan()

when I run this script, this is the error I keep getting.. help!

Exception caught :partially initialized module 'subprocess' has no attribute 'Popen' (most likely due to a circular import)
Exception caught : module 'subprocess' has no attribute 'Popen'

Upvotes: 1

Views: 5417

Answers (1)

alex_noname
alex_noname

Reputation: 32143

I suppose something is shadowing subprocess module. Try to do

import subprocess
subprocess.__file__

Upvotes: 4

Related Questions