ModuleNotFoundError:没有名为“脚本”的模块

发布于 2021-01-29 15:03:31

我试图通过和安装PYAHKpip install pyahk``python setup.py install

# pip --version
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)

# python --version
Python 3.6.1

这两个错误均显示以下消息:

Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\ca\AppData\Local\Temp\pip-build-as2lv10i\pyahk\setup.py", line 3, in <module>
    import ahk
    File "C:\Users\ca\AppData\Local\Temp\pip-build-as2lv10i\pyahk\ahk\__init__.py", line 7, in <module>
    from script import Function, Script
ModuleNotFoundError: No module named 'script'

但是…所讨论的模块.\ahk\script.py实际上确实存在

PYAHK
│   .hgignore
│   .hgtags
│   .hg_archival.txt
│   LICENSE.txt
│   pylintrc
│   README.rst
│   runtests.py
│   setup.py
│   __init__.py
│
├───ahk
│   │   ahk.py
│   │   control.py
│   │   script.py
│   │   __init__.py
│   │
│   └───__pycache__
│           __init__.cpython-36.pyc
│
├───doc
│   │   ahk.rst
│   │   conf.py
│   │   control.rst
│   │   index.rst
│   │   make.bat
│   │   script.rst
│   │
│   └───_templates
│           layout.html
│
└───test
        test_ahk.py
        test_control.py
        test_script.py
        __init__.py

有模块无法script.py在python3中命名的原因吗?我在安装过程中错过了什么吗?

关注者
0
被浏览
88
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    from script import在Python 2中是相对导入,但在Python
    3中成为绝对导入;没有全局模块“脚本”,因此错误。在Py3中,它必须是from ahk.script import或相对导入from .script import



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看