2

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?

SanguineL
  • 1,189
  • 1
  • 7
  • 18

3 Answers3

5

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()
Uday Chauhan
  • 1,071
  • 1
  • 9
  • 19
1

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.

user2357112
  • 260,549
  • 28
  • 431
  • 505
  • Wait. It didn't work. Still getting the same result. I have uninstalled pip, python-pptx, and python multiple times, but it didn't change at all. Is there anything else I have to do? – SanguineL Dec 03 '18 at 19:21
  • @SanguineL: Show us the output of `python -m pip show python-pptx` and `python -c 'import sys; print(sys.path)'`. – user2357112 Dec 03 '18 at 19:22
  • Edits added to post. – SanguineL Dec 03 '18 at 19:28
  • @SanguineL: Your `python` isn't Python 3.6 either. Figure out how to run your Python 3.6 from the shell, then use that Python to run `python -m pip ...`. – user2357112 Dec 03 '18 at 19:31
  • @SanguineL: Don't uninstall the system Python. You'll break things a lot worse than they are now. As for using Python 3.6, perhaps run `print(sys.executable)` in whatever unspecified shell you're using that's using Python 3.6, then use that Python to run pip. – user2357112 Dec 03 '18 at 19:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/184642/discussion-between-sanguinel-and-user2357112). – SanguineL Dec 03 '18 at 19:37
0

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.

ak_app
  • 170
  • 10