Reputation: 11
I've installed the pptx package using the following command:
pip install python-pptx
However, When ever I try to import the package this is the output I receive:
Traceback (most recent call last):
File "/Users/divyabahri/Documents/hello.py", line 5, in <module>
import pptx
ModuleNotFoundError: No module named 'pptx
Can someone please guide me regarding the latter issues, Thanks in Advance!
Upvotes: 1
Views: 10190
Reputation: 13
Running the code through any IDE may sometime cause this error. Happened with me when I tried to run through VScode. Try running it through python IDE or cmd just to check for, if opens you can sort out the editor issue.
Upvotes: 0
Reputation: 4957
Mismatch in the python version could be the cause of the error. The problem can be fixed by explicitly using PIP version 3 and also Python version 3.
Working demo:
Step 1: Install python-pptx and its dependencies using pip version 3
$ pip3 install python-pptx
$ pip3 install lxml ---> dependency
$ pip3 install pillow ---> dependency
Step 2: Python 3 program to create a pptx file
# File name: demo.py
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
prs.save('test.pptx')
Step 3: Execute the program using Python version 3
$ python3 demo.py
Step 4: Verify that the test.pptx file got created.
Upvotes: 1
Reputation: 675
There can be many reasons for that:
1.- Python pptx only supports python version 3.6 or less here is the documentation https://python-pptx.readthedocs.io/en/latest/user/install.html
2.- Check also your path, check if python version that is availabel for pptx is on the path, here you can see how to check your path, https://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-10/
3.- pip is outdated, try to upgrade your pip
4.- maybe you import bad the library, here you can see how to import it, https://python-pptx.readthedocs.io/en/latest/user/quickstart.html
Upvotes: 0