ModuleNotFoundError: No module named 'pdf2docx'
Question:
Look at this simple PDF to Docx converter, it needs pdf2docx module, although I have installed it manually using this code (py -m pip install pdf2dox) in CMD but still, it says (ModuleNotFoundError: No module named ‘pdf2docx’)
What am I doing wrong here, please?
Code:
from pdf2docx import Converter, parse
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter import messagebox
def choose_and_convert_file():
pdf_file = f"{askopenfilename()}"
if pdf_file == "":
messagebox.showwarning("Error", "Please choose a file!")
else:
file = pdf_file[:-4]
word_file = f"{file}.docx"
# Converter Method
cv = Converter(pdf_file)
cv.convert(word_file, start=0, end=None)
cv.close()
# Parse Method
# parse(pdf_file, word_file, start=0, end=None)
def space():
space = Label(text="", bg="black")
space.pack()
root = Tk()
root.title("PDF to Word Converter")
root.geometry("450x450")
root.columnconfigure(0, weight=1)
root.config(bg="black")
root.iconbitmap('icon.ico')
space()
space()
space()
img = PhotoImage(file="logo.png")
pic = Label(root, image=img, bg="black")
pic.pack()
space()
space()
space()
space()
choose_file = Button(width=23, height=1, bg="black", fg="white", text=" Choose and Convert",
font=("jost", 11, "bold"), command=choose_and_convert_file)
choose_file.pack()
space()
space()
space()
space()
space()
space()
space()
dev_label = Label(root, text="Developed by Totenkopf ", bg="black", fg="#CC1B25", font=("jost", 11))
dev_label.pack()
root.mainloop()
Answers:
I wanted to comment but I cannot. So, I’ll use the answer box.
You are intalling the package by py -m pip intall ...
and the module is installed in python version 3.10. But you are calling a python version 3.9 by C:Python39-32/... main.py
.
Try to run your program just with py main.py
with py
(only windows) you can decide what python version to use (if is correctly installed). You can list the version in your computer with py --list
and run the python version of you choice with py -3.9 main.py
or py -3.10 main.py
As pip is installing all your packages in Python 3.10
,
I would recommend that you locate the python.exe
for python 3.10 and then execute your command like this:
C:users......pythonpython310python.exe main.py
Alternatively, If you already have environment variables configured for python, you can run:
python main.py
- make sure that all words are spelled correctly,
- try different keywords,
- try more general keywords,
- try fewer keywords.
Solved, there was a bit of confusion I fell into, I was running my Python file with Python3.8 and I was using py -m pip install ModuleName
for installing the missing module.
So instead, I used:
python -m pip install ModuleName
Look at this simple PDF to Docx converter, it needs pdf2docx module, although I have installed it manually using this code (py -m pip install pdf2dox) in CMD but still, it says (ModuleNotFoundError: No module named ‘pdf2docx’)
What am I doing wrong here, please?
Code:
from pdf2docx import Converter, parse
from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter import messagebox
def choose_and_convert_file():
pdf_file = f"{askopenfilename()}"
if pdf_file == "":
messagebox.showwarning("Error", "Please choose a file!")
else:
file = pdf_file[:-4]
word_file = f"{file}.docx"
# Converter Method
cv = Converter(pdf_file)
cv.convert(word_file, start=0, end=None)
cv.close()
# Parse Method
# parse(pdf_file, word_file, start=0, end=None)
def space():
space = Label(text="", bg="black")
space.pack()
root = Tk()
root.title("PDF to Word Converter")
root.geometry("450x450")
root.columnconfigure(0, weight=1)
root.config(bg="black")
root.iconbitmap('icon.ico')
space()
space()
space()
img = PhotoImage(file="logo.png")
pic = Label(root, image=img, bg="black")
pic.pack()
space()
space()
space()
space()
choose_file = Button(width=23, height=1, bg="black", fg="white", text=" Choose and Convert",
font=("jost", 11, "bold"), command=choose_and_convert_file)
choose_file.pack()
space()
space()
space()
space()
space()
space()
space()
dev_label = Label(root, text="Developed by Totenkopf ", bg="black", fg="#CC1B25", font=("jost", 11))
dev_label.pack()
root.mainloop()
I wanted to comment but I cannot. So, I’ll use the answer box.
You are intalling the package by py -m pip intall ...
and the module is installed in python version 3.10. But you are calling a python version 3.9 by C:Python39-32/... main.py
.
Try to run your program just with py main.py
with py
(only windows) you can decide what python version to use (if is correctly installed). You can list the version in your computer with py --list
and run the python version of you choice with py -3.9 main.py
or py -3.10 main.py
As pip is installing all your packages in Python 3.10
,
I would recommend that you locate the python.exe
for python 3.10 and then execute your command like this:
C:users......pythonpython310python.exe main.py
Alternatively, If you already have environment variables configured for python, you can run:
python main.py
- make sure that all words are spelled correctly,
- try different keywords,
- try more general keywords,
- try fewer keywords.
Solved, there was a bit of confusion I fell into, I was running my Python file with Python3.8 and I was using py -m pip install ModuleName
for installing the missing module.
So instead, I used:
python -m pip install ModuleName