What to do when "cannot import name xxx" [Python]

Introduction

For some reason, there was a bug (ʻImportError: cannot import name'convert') that broke as follows at the import stage, so I will explain how to deal with it. This article talks about a package called docx2pdf`, but other packages have similar bugs, so I hope it helps those people as well.

python



Traceback (most recent call last):
  File "docx2pdf.py", line 5, in <module>
    from docx2pdf import convert
  File "/Users/xxx.py", line 5, in <module>
    from docx2pdf import convert
ImportError: cannot import name 'convert'

approach

The bottom line is that I was trying to import a package called dox2pdf, but I renamed the Python script to docx2pdf.py. A bug similar to the fact that reserved words cannot be used as variables is that the package name used cannot be used as a file name.

Therefore, when I changed the file name from docx2pdf.py to main.py, I was able to execute it safely.

Recommended Posts

What to do when "cannot import name xxx" [Python]
What to do when you can't bind CaboCha to Python
What to do when Ubuntu crashes
What to do with PYTHON release?
What to do when an error occurs with import _ssl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
What to do when a video cannot be read by cv2.VideoCapture
What to do if Insecure Platform Warning appears when running Python
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do when the value type is ambiguous in Python?
What to do when no display name occurs when unittesting Python + Tkinter on Github Actions Memo
[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement
[Python] What I did to do Unit Test
What to do if mod_fcgid cannot resolve UnicodeEncodeError
Investigation when import cannot be done with python
What to do if pip cannot be installed
What to do when PermissionError of tempfile.mkstemp occurs
What I did when updating from Python 2.6 to 2.7
What to do to get google spreadsheet in python
[Mac OS] What to do when Python is not installed as a framework. Is displayed when import matplotlib is performed.
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
[python] What to do when an error occurs in send_keys of headless chrome
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if you get an error when installing python with pyenv
What to do when [Errno 2] No such file or directory appears in Python
What I do when imitating embedded go in python
[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
What to do when raise ValueError, "unsupported hash type"
What to do if you are told "Import Error: cannot import name'HTTPSHandler'" when building a virtual environment using virtualenv
What I was addicted to when using Python tornado
I want to do something in Python when I finish
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do if "export" keeps appearing on terminal when trying to put Python on macOS
What to do when python3 type venv does not work well on Raspberry Pi
[Python] What to do when No module named'pyproj.datadir' appears when Exe is done with PyInstaller
What to do if you get an error when importing matplotlib in Python (Mac)
What to do when Python starts up in Anaconda does not come out unexpectedly
What to do if you get an Import Error when importing matplotlib with Jupyter
[Introduction to Python] What is the important "if __name__ =='__main__':" when dealing with modules?
[Python] if __name__ == What is'__main__' :?
ImportError: cannot resolve import name
ImportError: cannot resolve import name
[Python] Another way to import
[AWS] What to do when you want to pip with Lambda
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do when Japanese is not displayed on matplotlib
What to do if the package dependency cannot be repaired
What to do when PyCharm font is strange or garbled
What to do when Unalignable boolean Series provided as indexer
What I was addicted to when migrating Processing users to Python
What to do if package installation fails when deploying to heroku
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
Why django-import-export import is so slow and what to do
ImportError: No module What to do when you are told
What to do when you get an error saying "Name resolution temporarily failed" on linux
What to do when there is no response due to Proxy setting in Python web scraping
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()