我正在macOS Mojave (10.14.1)上运行Python3.6.6rc1,并试图导入Python。
目前,我的第一行引起了一个问题:
import python-pptx
我删除了它,并添加了这个,但没有结果。
from pptx import Presentation
这是我的错误:
ModuleNotFoundError: No module named 'pptx'
我使用pip下载python:
sudo pip install python-pptx
在终点站运行pip show python-pptx
,我得到:
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:
如您所见,Location
与Version
不同。这有问题吗?
在shell中运行sys.path
显示:
['/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']
运行python -m pip show python-pptx
,我得到了以下信息:
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:
不同的位置,但仍然在2.7
运行python -c'import sys; print(sys.path)'
会给我提供如下信息:
['', '/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']
如何修复此错误?
发布于 2020-06-07 18:46:12
您需要将python包安装为:
pip install python-pptx
您可以测试代码以验证安装:
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()
https://stackoverflow.com/questions/53599384
复制相似问题