SanguineL
SanguineL

Reputation: 1303

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?

Upvotes: 3

Views: 38834

Answers (4)

Hermes Fibonacci
Hermes Fibonacci

Reputation: 1

I had this problem running spiderfoot which also named this missing module I had to install it to the virtual environment in spiderfoot in that folder I was in (usr or home if you like/spiderfoot)

So maybe you need to invoke python first like

cd python pip install python-pptx

to install the module in the right path. It worked for me anyway.

Upvotes: 0

Uday Chauhan
Uday Chauhan

Reputation: 1148

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

Upvotes: 9

user2357112
user2357112

Reputation: 281949

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.

Upvotes: 1

ak_app
ak_app

Reputation: 170

Check if the module is available in any of the paths printed by "sys.path".
Either the module isn't installed or isn't available in module search path.

Upvotes: 0

Related Questions