我正在尝试在python程序中导入python pptx库。我之前用pip安装了它,它给了我以下输出:
Collecting python-pptx
Downloading python-pptx-0.6.6.tar.gz (8.4MB)
100% |████████████████████████████████| 8.4MB 132kB/s
Collecting Pillow>=2.6.1 (from python-pptx)
Downloading Pillow-4.2.1-cp27-cp27mu-manylinux1_x86_64.whl (5.8MB)
100% |████████████████████████████████| 5.8MB 193kB/s
Collecting XlsxWriter>=0.5.7 (from python-pptx)
Downloading XlsxWriter-0.9.8-py2.py3-none-any.whl (137kB)
100% |████████████████████████████████| 143kB 1.2MB/s
Collecting lxml>=3.1.0 (from python-pptx)
Downloading lxml-3.8.0-cp27-cp27mu-manylinux1_x86_64.whl (6.8MB)
100% |████████████████████████████████| 6.8MB 166kB/s
Collecting olefile (from Pillow>=2.6.1->python-pptx)
Downloading olefile-0.44.zip (74kB)
100% |████████████████████████████████| 81kB 1.3MB/s
Building wheels for collected packages: python-pptx, olefile
Running setup.py bdist_wheel for python-pptx ... done
Stored in directory: /home/clemens/.cache/pip/wheels/27/f8 /dc/181ed5439001413ee0c1c8794a06009c4c0b96f652401e2d20
Running setup.py bdist_wheel for olefile ... done
Stored in directory: /home/clemens/.cache/pip/wheels/20/58 /49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b
Successfully built python-pptx olefile
Installing collected packages: olefile, Pillow, XlsxWriter, lxml, python-pptx
Successfully installed Pillow-4.2.1 XlsxWriter-0.9.8 lxml-3.8.0 olefile-0.44 python-pptx-0.6.6
所以这似乎是成功的。 但是当我尝试使用以下代码导入模块时:
try:
from pptx import Presentation
except Exception as e:
print(e)
它说No module named 'pptx'
。
它必须与Linux有关,因为相同的代码在Windows上工作正常,并且模块似乎正确安装。我使用的是Python 3.5.3。
答案 0 :(得分:0)
使用pip install,你将为Python2而不是Python3安装它。为确保为Python3安装它,请从解释器调用pip,如下所示:
python3 -m pip install <package>