When executing the. py file with Jenkins Today, always prompt modulenotfounderror:no module named ' XXX ', baffled by its solution. But in the Pycharm is able to execute successfully, think and then run the. py file in the terminal, still prompt modulenotfounderror:no module named ' XXX '. It was later found that the package was not found when executing the. py file on the command line because we did not save the project path, you can save your project path by Sys.path.append (), and it will be successful after execution, as follows:
Import Sys
Print (Sys.path)
Import OS
#获取项目路径下的目录
Os.chdir (' Project path ')
#打印出项目路径下的目录
For file in Os.listdir (OS.GETCWD ()):
Print (file)
#将项目路径保存
Sys.path.append (' Project path ')
Note: If you want to import the package name of another module in the project, you should write the imported method after the method above, as follows:
Import Sys
Print (Sys.path)
Import OS
Os.chdir ('/a/b/c ')
For file in Os.listdir (OS.GETCWD ()):
Print (file)
Sys.path.append ('/a/b/c ')
From c.xx import D
At this point in the terminal through the Python xx.py will not prompt modulenotfounderror:no module named ' D '
---------------------
The flourishing of the first world.
Source: CSDN
Original: 78086768?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!
No module named "XXX" solution