0

i installed pdf2docx in virtual environment, pip install pdf2docx

(myapp) tt@sonictestbed-virtual-machine:~/Templates/New-journey/doc$ pip -V
pip 20.0.2 from /home/tt/Templates/New-journey/doc/myapp/lib/python3.8/site-packages/pip (python 3.8)
(myapp) tt@sonictestbed-virtual-machine:~/Templates/New-journey/doc$ python -V
Python 3.8.10
(myapp) tt@sonictestbed-virtual-machine:~/Templates/New-journey/doc$ pip list | grep pdf2docx
pdf2docx          0.5.6

here is the file pdf2docx.py:


pdf_file  = "test.pdf"
docx_file = "test.docx"

# Importing the Converter() class
from pdf2docx import Converter

# Specifying the pdf & docx files

try:
    # Converting PDF to Docx
    cv_obj = Converter(pdf_file)
    cv_obj.convert(docx_file)
    cv_obj.close()

except:
    print('Conversion Failed')
else:
    print('File Converted Successfully')


when i run the file, i got these

(myapp) tt@sonictestbed-virtual-machine:~/Templates/New-journey/doc$ python pdf2docx.py
Traceback (most recent call last):
  File "pdf2docx.py", line 6, in <module>
    from pdf2docx import Converter
  File "/home/tt/Templates/New-journey/doc/pdf2docx.py", line 6, in <module>
    from pdf2docx import Converter
ImportError: cannot import name 'Converter' from partially initialized module 'pdf2docx' (most likely due to a circular import) (/home/tt/Templates/New-journey/doc/pdf2docx.py)

I don't know why it is reporting an error circular import, any idea? Thanks in advance

1 Answers1

3

Did you name your script the same as the package? That will not work: your script will (try to) import your script, not the package. Hence the circular import error (the error even points directly to your script's path).

Rename your script.

9769953
  • 10,344
  • 3
  • 26
  • 37