简体   繁体   English

如何解决“无法导入名称'x'”的错误?

[英]How can I solve the error “Cannot import name 'x' ”?

I'm trying to convert Keras to a Core ML model but I'm stuck when converting the Python file into a mlmodel. 我正在尝试将Keras转换为Core ML模型,但是在将Python文件转换为mlmodel时遇到问题。

I'm getting errors when importing submodules of 'coremltools'. 导入“ coremltools”的子模块时出现错误。

The error that I'm getting is: "python recog.py Traceback (most recent call last): File "recog.py", line 3, in from coremltools import convert ImportError: cannot import name 'convert' " 我得到的错误是:“ python recog.py Traceback(最近一次调用最近):文件” recog.py“,第3行,来自coremltools import convert ImportError:无法导入名称'convert'”

I tried to import the submodules in a different way but nothing worked for me. 我试图以其他方式导入子模块,但对我没有任何帮助。

I hope anyone can help me! 希望任何人都能帮助我!

You can see the Python code, in the sample below: 您可以在下面的示例中看到Python代码:

import coremltools
from coremltools import converters
from coremltools import convert

coreml_model = coremltools.converters.keras.convert('model.h5', input_names='data', image_input_names='data', is_bgr=True, output_names='species')
coreml_model.save('model.mlmodel')

确保您要导入的名称在模块coremltools中。

In the file, coremtools.py double check if the name is same Ie convert. 在文件中,coremtools.py再次检查名称是否相同,即转换为相同名称。 Check the location of the coremtools.py file, is it in the main folder of python where python.exe exists? 检查coremtools.py文件的位置,是否在python.exe存在的python主文件夹中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决“无法从'virtualenv'导入名称'main'”? - How can I solve “cannot import name 'main' from 'virtualenv'”? 如何解决无法导入名称'ModuleName'错误? - How to solve cannot import name 'ModuleName' error? 我该如何解决这个不能 ImportError: cannot import name in python3 - How can I solve this cannot ImportError: cannot import name in python3 如何解决错误ImportError:无法导入名称'AsyncWebsocketConsumer'? - How to solve the error ImportError: cannot import name 'AsyncWebsocketConsumer'? 如何修复此错误?:ImportError:无法导入名称'titlescreen' - How can I fix this error?: ImportError: cannot import name 'titlescreen' 如何解决错误无法导入名称样式? - How can i resolve error cannot import name style? 如何解决抓取的导入错误 - How can I solve the Import error for scraping 无法在python中导入Difflib。 我怎么解决? - Cannot Import Difflib in python. How can I solve? 导入错误:无法从“collection.abc”导入名称“defautdict”如何解决? - import error: cannot import name "defautdict" from "collection.abc" how to solve this? Python导入模块错误,“导入错误:无法导入名称X” - Python Importing Module Error, “Import Error: cannot import name X”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM