简体   繁体   English

Python Import No Module Named错误

[英]Python Import No Module Named error

I pip installed pdfminer: https://pypi.python.org/pypi/pdfminer/20140328 on ubuntu 13.10 and that successfully installed into /usr/local/lib/python2.7/dist-packages/pdfminer 我在ubuntu 13.10上安装了pdfminer: https ://pypi.python.org/pypi/pdfminer/20140328并成功安装到/usr/local/lib/python2.7/dist-packages/pdfminer

when I try to run the example code: 当我尝试运行示例代码时:

from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfpage import PDFPage
from pdfminer.pdfpage import PDFTextExtractionNotAllowed
from pdfminer.pdfinterp import PDFResourceManager
from pdfminer.pdfinterp import PDFPageInterpreter
from pdfminer.pdfdevice import PDFDevice


if __name__=='__main__':
    # Open a PDF file.
    fp = open('MyPDF.pdf', 'rb')

I keep getting 我一直在

ImportError: No module named pdfparser

I have verified that pdfparser exists and there is a __init__.py file in the pdfminer folder. 我已经验证pdfparser存在并且pdfminer文件夹中有一个__init__.py文件。 I have tried recreating the __init__.py file. 我试过重新创建__init__.py文件。 I have also tried runing chmod -R 777 pdfminer but that doesn't fix it either. 我也试过运行chmod -R 777 pdfminer但这也没有解决它。

I have run env but there is no PYTHONPATH there is that a problem? 我已经运行了env但没有PYTHONPATH有问题吗? I have also tried installing PDFMiner into a virtualenv but that doesn't work either. 我也尝试将PDFMiner安装到virtualenv中,但这也不起作用。 I noticed that PDFMiner requires root permissions to install is that the problem? 我注意到PDFMiner需要root权限才能安装问题?

what am I doing wrong? 我究竟做错了什么?

Have you tried 你有没有尝试过

from pdfminer import pdfparser

or 要么

import pdfminer.pdfparser

?

Are you running the code from a file called pdfminer.py? 您是否正在运行名为pdfminer.py的文件中的代码?

This was causing the error in my case. 这导致了我的错误。 Python was trying to import the module from the file of the same name. Python试图从同名文件中导入模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM