Python 无法安装 PyPdf 2 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12780668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot install PyPdf 2 module
提问by geogeek
Trying to install PyPdf2module, I downloaded the zip and unzipped it, I executed python setup.py buildand python setup.py install, but it seems that it has not been installed , when I try to import it from a python script, it returns an ImportError:
尝试安装PyPdf2模块,我下载了 zip 并解压缩了它,我执行了python setup.py build和python setup.py install,但似乎尚未安装,当我尝试从 python 脚本导入它时,它返回一个ImportError:
import pyPdf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyPdf
Any help please.
请任何帮助。
I'm using python 2.7 under windows XP.
我在 Windows XP 下使用 python 2.7。
采纳答案by geogeek
It appears the README file for PyPDF2is incorrect. It suggests that
PyPDF2的 README 文件似乎不正确。它表明
import pyPdf
should work, but it doesn't. This new module is imported as
应该工作,但它没有。这个新模块被导入为
import PyPDF2
(as suggested by the document structure on github, and after verifying myself).
(如 github 上的文档结构所建议的,并经过我自己的验证)。
For convenience, when e.g. working with older code, you can of course do
为方便起见,例如在使用旧代码时,您当然可以这样做
import PyPDF2 as pyPdf
回答by anh_ng8
The PyPDF installer for Windows works well for me. (Win7-64) http://pybrary.net/pyPdf/
适用于 Windows 的 PyPDF 安装程序对我来说效果很好。(Win7-64) http://pybrary.net/pyPdf/
回答by Srikrishna Krishnarao Srinivas
Figured out so far what the issue is. Need to check if further commands of PyPDF2works. The import PyPDF2looks for PyPDF2folder in the base location of python. In my case it is C:\Python27\site-packages\PyPDF2.
到目前为止弄清楚是什么问题。需要检查进一步的命令是否PyPDF2有效。导入在 python 的基本位置中PyPDF2查找PyPDF2文件夹。就我而言,它是C:\Python27\site-packages\PyPDF2.
When virtualenv is activated, pip install PyPDF2does not create the above folder. Hence the error. I manually copied the PyPDF2 folder and PyPDF2-1.26.0.dist-infofolder from my virtualenv environment into the base folder above and the error stopped. Just in case, I created new virtualenv environment and installed PyPDF2 with and without virtualenv activated and the error is gone.
激活 virtualenv 时,pip installPyPDF2不会创建上述文件夹。因此错误。我手动将 PyPDF2 文件夹和PyPDF2-1.26.0.dist-info文件夹从我的 virtualenv 环境复制到上面的基本文件夹中,错误停止了。以防万一,我创建了新的 virtualenv 环境并安装了 PyPDF2,无论是否激活 virtualenv,错误都消失了。
My folder structure:
我的文件夹结构:
- C:\Python27\site-packages\PyPDF2
C:\Python27\site-packages\PyPDF2-1.26.0.dist-info
C:\Python27\venv2\Lib\site-packages\PyPDF2
- C:\Python27\venv2\Lib\site-packages\PyPDF2-1.26.0.dist-info
- C:\Python27\site-packages\PyPDF2
C:\Python27\site-packages\PyPDF2-1.26.0.dist-info
C:\Python27\venv2\Lib\site-packages\PyPDF2
- C:\Python27\venv2\Lib\site-packages\PyPDF2-1.26.0.dist-info
Python script is very simple to test the import:
测试导入的 Python 脚本非常简单:
#import sys
import PyPDF2
#print(sys.path)
print('hello')
I troubleshooted the above using the stackoverflow response to check syspath How does python find a module file if the import statement only contains the filename?
我使用 stackoverflow 响应来检查 syspath 如果导入语句只包含文件名,python 如何找到模块文件?

