python - 即使我安装了包,在 makefile 上构建 python 包时出错
问题描述
我正在尝试为某个项目运行makefile,但即使在运行make init 时一切都成功了,我在make 运行期间也遇到了很多错误。目前我在 conda 环境中运行这个 makefile
我什至检查了有错误的文件并直接使用 python blablabla.py 运行它,它运行完美,但是当我运行 makefile 时,它在同一个文件上显示为错误
all: build
init:
@which python3 > /dev/null 2>&1 || (echo "python3 is not installed on this system" && exit 1)
@which pip3 > /dev/null 2>&1 || (echo "pip3 is not installed on this system" && exit 1)
@echo "Installing requirements with pip3..."
@while read package; \
do \
line="$$package"; \
[[ "$$line" == git+* ]] && \
line=`echo "$$line" | sed -e 's/git.*\///g' -e 's/.git$$//g'`; \
pip3 freeze 2>/dev/null | grep -P `echo "$$line" | sed 's/>=/.*/g'` > /dev/null 2>&1 || \
pip3 install --user "$$package"; \
done < requirements.txt
build: init build-lang
@echo "Building python package..."
@mypy --package color_harmonization
@echo "#! /bin/bash" > color-harmonization
@echo "/usr/bin/env python3 -m color_harmonization" >> color-harmonization
@chmod +x color-harmonization
run: build
@echo "Running application..."
@./color-harmonization
lang:
@echo "Generating internationalization files..."
@mkdir -p color_harmonization/gui/locale/de_DE/LC_MESSAGES
@intltool-extract --type=gettext/glade color_harmonization/gui/color-harmonization.glade
@xgettext --from-code=UTF-8 --language=Python --keyword=_ --keyword=N_ \
--output=color_harmonization/gui/locale/locale.pot \
`find . -name "*.py" -type f` \
color_harmonization/gui/color-harmonization.glade.h
@msginit --input=color_harmonization/gui/locale/locale.pot \
--locale=de_DE.UTF-8 --output-file=color_harmonization/gui/locale/de_DE/LC_MESSAGES/de_DE.po
build-lang:
@echo "Compiling internationalization files..."
@msgfmt --output color_harmonization/gui/locale/de_DE/LC_MESSAGES/color_harmonization.mo \
color_harmonization/gui/locale/de_DE/LC_MESSAGES/de_DE.po
这些是构建makefile的错误
Compiling internationalization files...
Building python package...
color_harmonization/gui/gl_widget.py:21: error: No library stub file for module 'gi.repository'
color_harmonization/gui/gl_widget.py:22: error: Cannot find implementation or library stub for module named 'OpenGL'
color_harmonization/gui/__init__.py:19: error: Name 'List' is not defined
color_harmonization/gui/__init__.py:19: note: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
color_harmonization/__init__.py:19: error: Name 'List' is not defined
color_harmonization/__init__.py:19: note: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
color_harmonization/handler.py:20: error: No library stub file for module 'gi.repository'
color_harmonization/gui/hue_sat_wheel_widget.py:20: error: No library stub file for module 'numpy'
color_harmonization/gui/hue_sat_wheel_widget.py:22: error: Cannot find implementation or library stub for module named 'cairocffi'
color_harmonization/gui/hue_sat_wheel_widget.py:25: error: No library stub file for module 'gi.repository'
color_harmonization/gui/gl_quad_renderer.py:19: error: No library stub file for module 'numpy'
color_harmonization/gui/gl_quad_renderer.py:23: error: Cannot find implementation or library stub for module named 'OpenGL'
color_harmonization/gui/gl_quad_renderer.py:24: error: Cannot find implementation or library stub for module named 'pyrr'
color_harmonization/gui/gl_quad_renderer.py:25: error: No library stub file for module 'PIL'
color_harmonization/gui/gl_image.py:19: error: No library stub file for module 'gi.repository'
color_harmonization/gui/assistant.py:24: error: No library stub file for module 'gi.repository'
color_harmonization/gui/assistant.py:24: note: (Stub files are from https://github.com/python/typeshed)
color_harmonization/gui/assistant.py:39: error: Module has no attribute "bindtextdomain"
color_harmonization/gui/assistant.py:104: error: Incompatible types in assignment (expression has type "None", variable has type "List[str]")
color_harmonization/gui/assistant.py:105: error: Incompatible types in assignment (expression has type "None", variable has type "str")
color_harmonization/__main__.py:22: error: Cannot find implementation or library stub for module named 'gi'
color_harmonization/__main__.py:22: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 18 errors in 9 files (checked 12 source files)
Makefile:33: recipe for target 'build' failed
make: *** [build] Error 1
这是一个python文件,因为它有很多,我只发布第一个python文件出错
import abc
from gi.repository import Gtk, Gdk
from OpenGL import GL
class GLRenderer (metaclass = abc.ABCMeta):
@property
def gl_widget (self: 'GLRenderer') -> 'GLWidget':
return self.__gl_widget
@gl_widget.setter
def gl_widget (self: 'GLRenderer', value: 'GLWidget') -> None:
self.__gl_widget = value
def make_current (self: 'GLRenderer') -> None:
self.gl_widget.make_current ()
@abc.abstractmethod
def load (self: 'GLRenderer') -> None:
pass
@abc.abstractmethod
def update (self: 'GLRenderer') -> None:
pass
@abc.abstractmethod
def resize (self: 'GLRenderer', width: int, height: int) -> None:
GL.glViewport (0, 0, width, height)
@abc.abstractmethod
def render (self: 'GLRenderer') -> None:
GL.glClear (GL.GL_COLOR_BUFFER_BIT)
GL.glClearColor (0, 0, 0, 0)
class GLWidget (Gtk.Overlay):
def __init__ (self: 'GLWidget', renderer: GLRenderer,
gl_major_version: int, gl_minor_version: int) -> None:
super ().__init__ ()
self.renderer = renderer
self.renderer.gl_widget = self
self.gl_area = Gtk.GLArea ()
self.gl_area.set_required_version (gl_major_version, gl_minor_version)
self.gl_area.props.has_alpha = True
self.gl_area.props.has_depth_buffer = False
self.gl_area.props.auto_render = True
self.gl_area.connect ('render', self.__handle_render)
self.gl_area.connect ('realize', self.__handle_realize)
self.gl_area.connect ('resize', self.__handle_resize)
self.add_overlay (self.gl_area)
self.props.expand = True
self.__width = 400
self.__height = 300
def __handle_render (self: 'GLWidget', gl_area: Gtk.GLArea, context: Gdk.GLContext) -> None:
self.renderer.render ()
def __handle_realize (self: 'GLWidget', gl_area: Gtk.GLArea) -> None:
self.renderer.load ()
def __handle_resize (self: 'GLWidget', gl_area: Gtk.GLArea, width: int, height: int) -> None:
self.__width = width
self.__height = height
self.renderer.resize (width, height)
@property
def width (self: 'GLWidget') -> int:
return self.__width
@property
def height (self: 'GLWidget') -> int:
return self.__height
def make_current (self: 'GLWidget') -> None:
self.gl_area.make_current ()
请查看此github 链接以获取完整的源代码。我将不胜感激任何建议和帮助谢谢
解决方案
问题似乎是 mypy 找不到模块。python gl_widget.py
当您在没有导入错误的情况下运行时,这些模块似乎在您的系统上安装得很好。
请研究 mypy 手册并实施其中提到的步骤:https ://mypy.readthedocs.io/en/stable/running_mypy.html#finding-imports
如果这不能解决您的问题或您仍有疑问,请再问一个问题。这次没有标记 makefile 而只有 mypy 和 python。因为这不是 makefile 问题,而是 mypy 和 python 模块查找问题。
此外,由于您的用户名是“wanttobepro”,因此学习做最少的可重复示例对您成为专业人士非常有帮助。请学习做最少的可重复示例。
阅读此处了解更多信息:https ://stackoverflow.com/help/minimal-reproducible-example
甚至更多:https ://duckduckgo.com/?q=minimal+reproducible+examples&t=ffab&ia=web
推荐阅读
- android - 通过传递布局 id 避免手动膨胀布局
- reactjs - React 表单中的两个下拉菜单
- arrays - 如何释放使用 malloc 分配的二维数组?
- python - 无法在 OSX / Python 3.9 上安装 pyarrow:这是我还是不兼容的包?
- python - CNN 准确性不会在多个时期内发生变化
- python - 机器人如何检测垃圾邮件行或多行无用文本?
- reactjs - create-react-app my-app --typescript 与 --template typscript
- winforms - 从 http flurl 客户端捕获异常的问题
- java - Intellij DialogWrapper 和 Balloon 通知
- java - 包结构和带有清单的 jar 文件