找不到PPTX包

2024-10-04 01:35:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用以下命令安装了pptx包:
pip install python-pptx

但是,当我尝试导入软件包时,这是我收到的输出:

Traceback (most recent call last):
  File "/Users/divyabahri/Documents/hello.py", line 5, in <module>
    import pptx
ModuleNotFoundError: No module named 'pptx

请有人就后一个问题指导我,提前谢谢


Tags: installpip命令mosthellocallusersdocuments
2条回答

原因可能有很多:

1.-Python pptx仅支持Python版本3.6或更低版本,这是文档https://python-pptx.readthedocs.io/en/latest/user/install.html

2.-还要检查您的路径,检查pptx可用的python版本是否在路径上,在这里您可以看到如何检查您的路径https://winaero.com/blog/how-to-see-names-and-values-of-environment-variables-in-windows-10/

3.-pip已过时,请尝试升级您的pip

4.-也许你导入了坏库,在这里你可以看到如何导入它,https://python-pptx.readthedocs.io/en/latest/user/quickstart.html

python版本中的不匹配可能是错误的原因。这个问题可以通过显式使用PIP版本3和Python版本3来解决

工作演示:

步骤1:使用pip版本3安装python pptx及其依赖项

$ pip3 install python-pptx
$ pip3 install lxml            -> dependency
$ pip3 install pillow          -> dependency

步骤2:Python 3程序创建pptx文件

# File name:  demo.py

from pptx import Presentation 
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.text = "Hello, World!" 
subtitle.text = "python-pptx was here!" 
prs.save('test.pptx')

步骤3:使用Python版本3执行程序

$ python3 demo.py 

步骤4:验证是否创建了test.pptx文件。 enter image description here

相关问题 更多 >