No module named "XXX" solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.