导入 python-pptx:ModuleNotFoundError:没有名为“pptx"的模块 [英] Importing python-pptx: ModuleNotFoundError: No module named 'pptx'

查看:127
本文介绍了导入 python-pptx:ModuleNotFoundError:没有名为“pptx"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 macOS Mojave (10.14.1) 上运行 Python 3.6.6rc1,我正在尝试导入 python-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'

<小时>

我已经使用 pip 下载了 python-pptx:


I have downloaded python-pptx using pip:

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: 

如您所见,LocationVersion 不同.有问题吗?

As you can see, the Location is different than the Version. Is that a problem?

在 shell 中运行 sys.path 显示:

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']

<小时>

运行 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']

<小时>

我该如何解决这个错误?


How do I fix this error?

推荐答案

您已经安装了 python-pptx 和对应于系统 Python 2.7 的 pip,而不是您尝试使用的 Python 3.6.用

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 ...

代替

sudo pip install ...

确保您为 Python 使用正确的 pip,并避免与通过 sudo 运行 pip 相关的一些其他问题.

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.

这篇关于导入 python-pptx:ModuleNotFoundError:没有名为“pptx"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆