我的nox会话定义如下:
@nox.session(python=["3.10", "3.9.10"])
def mypy(session: Session) -> None:
args = session.posargs or locations
install_with_constraints(session, "mypy")
session.run("mypy", *args)
def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None:
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--dev",
"--format=requirements.txt",
"--without-hashes",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)我有一个模块,我用标准的方式导入numpy:
import numpy as np
...some code...PyCharm在这个导入方面没有问题,例如,如果我导入torch,它会警告我没有类型存根。然而,当我运行nox时,我得到:
error: Cannot find implementation or library stub for module named "numpy"为什么Mypy在nox会话内部运行时找不到Numpy存根?
发布于 2022-05-07 20:02:05
Numpy 在1.20版中引入类型存根.如果使用低于1.20的numpy版本,请安装numpy存根。如果使用numpy 1.20或更高版本,则不应出现此问题。
https://stackoverflow.com/questions/71189281
复制相似问题