简体   繁体   中英

ImportError: cannot import name 'convert_from_path'

这是我的代码和错误

I am trying to convert pdf to image. So I'm doing it using the pdf2image library. But somehow I get this error

ImportError: cannot import name 'convert_from_path'

keeps showing up. When I try to run the same code in command prompt it seems to work. But in Sublime editor this error keeps showing up.

From your error message, you seem to have a file named pdf2image.py in the same directory as your main script.

File "/home/raheeb/Downloads/Telegram Desktop/New python/pdf_conversion.py" ...
  from pdf2image.exceptions import convert_from_path
File "/home/raheeb/Downloads/Telegram Desktop/New python/pdf2image.py" ...
  from pdf2image import convert_from_path                     ^^
                                                              ||
                                                              ||

You need to rename that, because your main script is importing from that pdf2image.py instead of the actual pdf2image module which I assume is what you have installed and should be the one you actually need.

As to why it imports that instead of the true module, you need to read the Module Search Path from the Python docs. Basically, it first searches for modules in the same directory as your script, before it searches from the installation environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM