ImportError: cannot import name 'main' from partially initialized module ' ' (most likely due to a circular import)
ImportError: cannot import name 'main' from partially initialized module ' ' (most likely due to a circular import)
我创建了一个 Pentest 工具用于教育目的,所以旧版本是使用 python 2 编写的,然后我将其转换为 python 3,当我尝试 运行主文件 pxxtf.py
我遇到了多个错误,我更正了其中的大部分错误,但是对于这个关于循环导入的错误,我尝试了来自论坛和 Whosebug 的多个修复,但没有任何效果。
当我尝试 运行 主脚本时 :
sudo python3 pxxtf.py
我遇到了这些错误:
Traceback (most recent call last):
File "pxxtf.py", line 6, in <module>
from core.excute import main
File "/home/yezz123/Documents/PXXTF/core/excute.py", line 6, in <module>
from pxxtf import *
File "/home/yezz123/Documents/PXXTF/pxxtf.py", line 6, in <module>
from core.excute import main
ImportError: cannot import name 'main' from partially initialized module 'core.excute' (most likely due to a circular import) (/home/yezz123/Documents/PXXTF/core/excute.py)
- 对于代码,这是主要的
pxxtf.py
from core.excute import main
if __name__ == "__main__":
main()
import sys
from core.excute import main
if __name__ == 'main':
sys.exit(main._main())
这是 excute.py
import os
import sys
import core
from time import sleep, time
from pxxtf import *
from core.exploit import clean
from core.banner import banner, PXXTF
# Set color
R = '3[31m' # Red
N = '3[1;37m' # White
G = '3[32m' # Green
O = '3[0;33m' # Orange
B = '3[1;34m' #Blue
E = '3[0m' # End
if not os.geteuid() == 0: #Detected user root
sys.exit(
"""3[1;91m\n[!] Pentest Tools Framework run as root!!. \n3[1;m"""
)
if __name__ == "__main__" or clean() or banner() or PXXTF():
main()
def main():
while True:
try:
PXXTF = eval(input("Pentest>> "))
if PXXTF == 'use modules/exploits':
core.menu.exploits()
main()
elif PXXTF == 'use modules/scanners':
core.menu.scan()
main()
elif PXXTF == 'use modules/password':
core.menu.pas1()
main()
elif PXXTF == 'use modules/post':
core.menu.post()
main()
elif PXXTF == 'use modules/listener':
core.menu.listener()
main()
elif PXXTF == 'use modules/exploitdb':
core.menu.exploit_db()
main()
elif PXXTF == 'use modules/tools':
core.menu.tools()
main()
elif PXXTF == 'shell':
core.exploit.commands()
main()
elif PXXTF == 'show modules':
core.help.modules()
main()
elif PXXTF == 'ipconfig':
core.exploit.ip1()
main()
elif PXXTF == 'show options':
core.help.help()
main()
elif PXXTF == 'update':
core.exploit.update()
main()
elif PXXTF == 'about':
core.banner.info()
main()
elif PXXTF == 'credits':
core.banner.credits()
main()
elif PXXTF == 'banner':
clean(), banner(), PXXTF(), main()
elif PXXTF == 'clear':
core.menu.exploit.clean()
main()
elif PXXTF == 'exit':
core.banner.exits()
exit()
else:
print(("Wrong Command => ", PXXTF))
print(("" + N + "" + B + "[" + R + "!" + B + "] " + N +
"Please enter 'show options'"))
main()
except (KeyboardInterrupt):
print(
("\n" + R + "[*] (Ctrl + C ) Detected, Trying To Exit ...\n"))
time.sleep(2)
print(("" + G + "[*] Thank You For Using Pentest Framework =)\n"))
time.sleep(3)
exit()
- 要测试完整代码,您可以在此处找到它:
https://github.com/gdgsnf/PXXTF
错误消息说明了一切:“很可能是由于循环导入”。
pxxtf.py
from core.excute import main
excute.py
from pxxtf import *
删除上面列出的导入之一,它应该可以工作。无论哪种方式,在 Python 中你都不能让脚本相互导入。
我创建了一个 Pentest 工具用于教育目的,所以旧版本是使用 python 2 编写的,然后我将其转换为 python 3,当我尝试 运行主文件 pxxtf.py
我遇到了多个错误,我更正了其中的大部分错误,但是对于这个关于循环导入的错误,我尝试了来自论坛和 Whosebug 的多个修复,但没有任何效果。
当我尝试 运行 主脚本时 :
sudo python3 pxxtf.py
我遇到了这些错误:
Traceback (most recent call last):
File "pxxtf.py", line 6, in <module>
from core.excute import main
File "/home/yezz123/Documents/PXXTF/core/excute.py", line 6, in <module>
from pxxtf import *
File "/home/yezz123/Documents/PXXTF/pxxtf.py", line 6, in <module>
from core.excute import main
ImportError: cannot import name 'main' from partially initialized module 'core.excute' (most likely due to a circular import) (/home/yezz123/Documents/PXXTF/core/excute.py)
- 对于代码,这是主要的
pxxtf.py
from core.excute import main
if __name__ == "__main__":
main()
import sys
from core.excute import main
if __name__ == 'main':
sys.exit(main._main())
这是 excute.py
import os
import sys
import core
from time import sleep, time
from pxxtf import *
from core.exploit import clean
from core.banner import banner, PXXTF
# Set color
R = '3[31m' # Red
N = '3[1;37m' # White
G = '3[32m' # Green
O = '3[0;33m' # Orange
B = '3[1;34m' #Blue
E = '3[0m' # End
if not os.geteuid() == 0: #Detected user root
sys.exit(
"""3[1;91m\n[!] Pentest Tools Framework run as root!!. \n3[1;m"""
)
if __name__ == "__main__" or clean() or banner() or PXXTF():
main()
def main():
while True:
try:
PXXTF = eval(input("Pentest>> "))
if PXXTF == 'use modules/exploits':
core.menu.exploits()
main()
elif PXXTF == 'use modules/scanners':
core.menu.scan()
main()
elif PXXTF == 'use modules/password':
core.menu.pas1()
main()
elif PXXTF == 'use modules/post':
core.menu.post()
main()
elif PXXTF == 'use modules/listener':
core.menu.listener()
main()
elif PXXTF == 'use modules/exploitdb':
core.menu.exploit_db()
main()
elif PXXTF == 'use modules/tools':
core.menu.tools()
main()
elif PXXTF == 'shell':
core.exploit.commands()
main()
elif PXXTF == 'show modules':
core.help.modules()
main()
elif PXXTF == 'ipconfig':
core.exploit.ip1()
main()
elif PXXTF == 'show options':
core.help.help()
main()
elif PXXTF == 'update':
core.exploit.update()
main()
elif PXXTF == 'about':
core.banner.info()
main()
elif PXXTF == 'credits':
core.banner.credits()
main()
elif PXXTF == 'banner':
clean(), banner(), PXXTF(), main()
elif PXXTF == 'clear':
core.menu.exploit.clean()
main()
elif PXXTF == 'exit':
core.banner.exits()
exit()
else:
print(("Wrong Command => ", PXXTF))
print(("" + N + "" + B + "[" + R + "!" + B + "] " + N +
"Please enter 'show options'"))
main()
except (KeyboardInterrupt):
print(
("\n" + R + "[*] (Ctrl + C ) Detected, Trying To Exit ...\n"))
time.sleep(2)
print(("" + G + "[*] Thank You For Using Pentest Framework =)\n"))
time.sleep(3)
exit()
- 要测试完整代码,您可以在此处找到它: https://github.com/gdgsnf/PXXTF
错误消息说明了一切:“很可能是由于循环导入”。
pxxtf.py
from core.excute import main
excute.py
from pxxtf import *
删除上面列出的导入之一,它应该可以工作。无论哪种方式,在 Python 中你都不能让脚本相互导入。