RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1033990
Accepted
finally
finally
Asked:2020-10-13 01:18:40 +0000 UTC2020-10-13 01:18:40 +0000 UTC 2020-10-13 01:18:40 +0000 UTC

ModuleNotFoundError:没有名为“异常”的模块/ ModuleNotFoundError:没有名为“docx”的模块

  • 772

您需要打开一个 Microsoft Word 文件(.doc、.docx)进行读写操作:

pip install docx
pip install python-docx

这两个命令都出现以下错误:

ModuleNotFoundError: No module named 'docx'

我也尝试使用 PyCharm 本身:

import docx
from docx import Document

点击弹出错误直接从 PyCharm 安装包,得到这个:

ModuleNotFoundError: No module named 'exceptions'

如果需要,这是代码

from docx import Document


file = r'C:\Users\fsoci\Desktop\d.docx'#input('full path: ')

def getText(filename):
    doc = Document(filename)
    fullText = []
    for para in doc.paragraphs:
        fullText.append(para.text)
    return '\n'.join(fullText)

print(getText(file))

无论我重新安装docx和python-docx多少次,仍然有这些错误,可能是什么问题??

提前致谢!

python
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    gil9red
    2020-10-26T05:51:50Z2020-10-26T05:51:50Z

    视窗 10,蟒蛇 3.7.3

    确保在项目设置中解释器与您安装模块的解释器相同。可能是在创建项目的时候,选择了venv的创建——解释器的单独副本,如果没有激活venv,全局pip会安装到原来的python文件夹,venv保持不变


    安装:

    C:\Users\ipetrash> pip install docx                                                                                                                         
    Collecting docx                                                                                                                                             
      Downloading https://files.pythonhosted.org/packages/4a/8e/5a01644697b03016de339ef444cfff28367f92984dc74eddaab1ed60eada/docx-0.2.4.tar.gz (54kB)           
         |████████████████████████████████| 61kB 491kB/s                                                                                                        
    Requirement already satisfied: lxml in c:\users\ipetrash\anaconda3\lib\site-packages (from docx) (4.3.4)                                                    
    Requirement already satisfied: Pillow>=2.0 in c:\users\ipetrash\anaconda3\lib\site-packages (from docx) (6.1.0)                                             
    Building wheels for collected packages: docx                                                                                                                
      Building wheel for docx (setup.py) ... done                                                                                                               
      Stored in directory: C:\Users\ipetrash\AppData\Local\pip\Cache\wheels\cc\8d\09\563edfd874a35c0c7ed129b6c4fa890efa4c26458bdec6ffc1                         
    Successfully built docx                                                                                                                                     
    Installing collected packages: docx                                                                                                                         
    Successfully installed docx-0.2.4                                                                                                                           
    
    C:\Users\ipetrash> pip install python-docx                                                                                                                  
    Collecting python-docx                                                                                                                                      
      Downloading https://files.pythonhosted.org/packages/e4/83/c66a1934ed5ed8ab1dbb9931f1779079f8bca0f6bbc5793c06c4b5e7d671/python-docx-0.8.10.tar.gz (5.5MB)  
         |████████████████████████████████| 5.5MB 595kB/s                                                                                                       
    Requirement already satisfied: lxml>=2.3.2 in c:\users\ipetrash\anaconda3\lib\site-packages (from python-docx) (4.3.4)                                      
    Building wheels for collected packages: python-docx                                                                                                         
      Building wheel for python-docx (setup.py) ... done                                                                                                        
      Stored in directory: C:\Users\ipetrash\AppData\Local\pip\Cache\wheels\18\0b\a0\1dd62ff812c857c9e487f27d80d53d2b40531bec1acecfa47b                         
    Successfully built python-docx                                                                                                                              
    Installing collected packages: python-docx                                                                                                                  
    Successfully installed python-docx-0.8.10                                                                                                                   
    

    模块运行检查:

    C:\Users\ipetrash> python                                                                                                                                   
    Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32                                                        
    
    Warning:                                                                                                                                                    
    This Python interpreter is in a conda environment, but the environment has                                                                                  
    not been activated.  Libraries may fail to load.  To activate this environment                                                                              
    please see https://conda.io/activation                                                                                                                      
    
    Type "help", "copyright", "credits" or "license" for more information.                                                                                      
    >>> from docx import Document                                                                                                                               
    >>> Document                                                                                                                                                
    <function Document at 0x0000017E010D9378>                                                                                                                   
    >>>                                                                                                                                                         
    
    • 2
  2. S. Nick
    2020-10-13T02:14:09Z2020-10-13T02:14:09Z

    一切正常:

    pip install python-docx
    
    D:\_Qt\__Qt>pip install python-docx
    Collecting python-docx
      Downloading https://files.pythonhosted.org/packages/e4/83/c66a1934ed5ed8ab1dbb9931f1779079f8bca0f6bbc5793c06c4b
    on-docx-0.8.10.tar.gz (5.5MB)
         |████████████████████████████████| 5.5MB 437kB/s
    Requirement already satisfied: lxml>=2.3.2 in c:\users\user\appdata\local\programs\python\python37\lib\site-packa
    thon-docx) (4.3.3)
    Installing collected packages: python-docx
      Running setup.py install for python-docx ... done
    Successfully installed python-docx-0.8.10
    

    from docx import Document
    
    symbols = {' ': ' ',
               'е': 'e',
               'у': 'y',
               'о': 'o',
               'з': '3',
               'р': 'p',
               'а': 'a',
               'х': 'x',
               'к': 'k',
               ',': '‚',
               '"': '”'}
    # file = r'C:\Users\fsoci\Desktop\d.docx'#input('full path: ')
    file = r'D:/_Qt/__Qt/d.docx'
    
    def getText(filename):
        doc = Document(filename)
        fullText = []
        for para in doc.paragraphs:
            fullText.append(para.text)
    
        return '\n'.join(fullText)
    
    print(getText(file))
    

    D:\_Qt\__Qt>py aa.py
    exec("self.labelList.append("+"self.X"+str(i)+")")
    
    
    D:\_Qt\__Qt>
    
    • 0

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5