[英]How can you see what import fails in an imported module?
I need to make a portable app to put on a device and I want to put only the modules needed so there will not be all the standard modules so I need to see what my app needs, but if that module misses some imports I cannot see that, because it gives an error without being explicit what fails in that module: 我需要制作一个可移植的应用程序以放置在设备上,并且只想放置所需的模块,因此不会有所有标准模块,因此我需要查看应用程序的需求,但是如果该模块缺少某些导入,我将看不到那是因为它给出了一个错误而没有明确指出该模块中失败的原因:
Traceback (most recent call last):
File "./packaging.py", line 30, in <module>
import simplejson
ImportError: No module named simplejson
Is there a way to see what import exactly fails in that module? 有没有办法查看该模块中的导入完全失败?
The error means, that the import import simplejson
fails because there is “[n]o module named simplejson” . 该错误意味着,由于存在“ [n] o名为simplejson的模块” ,所以import
import simplejson
失败。 The solution is to simply install said module . 解决方法是简单地安装所述模块 。
you can catch the exceptions, to know what went wrong and handle them appropriately: 您可以捕获异常,以了解出了什么问题并适当地处理它们:
try:
import simplejson
except ImportError:
print "simplejson module not found"
#or do something else here, may be install that module
可能是字符串/usr/lib/python2.7/dist-packages
不在sys.path
文件夹列表中,因此在尝试导入模块或软件包时不会搜索该字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.