Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing python-pptx: ModuleNotFoundError: No module named 'pptx'

I'm running Python 3.6.6rc1 on macOS Mojave (10.14.1) and I'm trying to import python-pptx

Currently, my first line is causing a problem:

import python-pptx

I deleted that and added this, to no avail.

from pptx import Presentation

This is my error:

ModuleNotFoundError: No module named 'pptx'

I have downloaded python-pptx using pip:

sudo pip install python-pptx

Running pip show python-pptx in the Terminal, I get:

Name: python-pptx
Version: 0.6.16
Summary: Generate and manipulate Open XML PowerPoint (.pptx) files
Home-page: http://github.com/scanny/python-pptx
Author: Steve Canny
Author-email: [email protected]
License: The MIT License (MIT)
Location: /Library/Python/2.7/site-packages
Requires: lxml, Pillow, XlsxWriter
Required-by: 

As you can see, the Location is different than the Version. Is that a problem?


Running sys.path in the shell shows:

['/Users/gstrickland/Desktop', '/Users/gstrickland/Documents', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']

Running python -m pip show python-pptx I get this:

Name: python-pptx
Version: 0.6.16
Summary: Generate and manipulate Open XML PowerPoint (.pptx) files
Home-page: http://github.com/scanny/python-pptx
Author: Steve Canny
Author-email: [email protected]
License: The MIT License (MIT)
Location: /Users/gstrickland/Library/Python/2.7/lib/python/site-packages
Requires: lxml, Pillow, XlsxWriter
Required-by: 

Different location, but still in 2.7


Running python -c'import sys; print(sys.path)' gives me:

['', '/Library/Python/2.7/site-packages/pip-18.1-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Users/gstrickland/Library/Python/2.7/lib/python/site-packages', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

How do I fix this error?

like image 298
SanguineL Avatar asked Sep 19 '25 05:09

SanguineL


2 Answers

You need to install python-pptx package as :

pip install python-pptx

You can test the code to verify installation :

from pptx import Presentation


def main():
    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.tetx = "Hello World fromm pptx"
    subtitle.text = "using python-ppts!!!"
    prs.save("test.pptx")


if __name__ == "__main__":
    main()
like image 73
Uday Chauhan Avatar answered Sep 21 '25 20:09

Uday Chauhan


You've installed python-pptx with a pip corresponding to the system Python 2.7, not the Python 3.6 you're trying to use. Install things with

python -m pip install --user ...

instead of

sudo pip install ...

to ensure you're using the right pip for your Python, and to avoid some of the other problems associated with running pip through sudo.

like image 27
user2357112 supports Monica Avatar answered Sep 21 '25 21:09

user2357112 supports Monica