ModuleNotFoundError:没有名为“脚本"的模块 [英] ModuleNotFoundError: No module named 'script'
问题描述
我试图通过pip 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
这两个错误均显示以下消息:
both of these error out with the following message:
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
However ... the module in question .\ahk\script.py
does in fact exist
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
在python3中不能将模块命名为script.py
的原因吗?我在安装过程中错过了什么吗?
is there a reason that a module cant be named script.py
in python3? Did I miss something in the install?
推荐答案
from script import
在Python 2中是相对导入,但在Python 3中成为绝对导入;没有全局模块脚本",因此错误.在Py3中,它必须为from ahk.script import
或相对导入from .script import
.
from script import
was a relative import in Python 2 but became an absolute import in Python 3; there is no global module 'script' hence the error. In Py3 it must be from ahk.script import
or relative import from .script import
.
这篇关于ModuleNotFoundError:没有名为“脚本"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!