pythonmodulepython-pptx

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: python-pptx@googlegroups.com
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: python-pptx@googlegroups.com
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?


Solution

  • 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()