gpt4 book ai didi

python - 即使我安装了软件包,在 makefile 上构建 python 软件包时出错

转载 作者:行者123 更新时间:2023-12-01 07:00:51 28 4
gpt4 key购买 nike

我正在尝试为某个项目运行 makefile,但是即使在运行 make init 时一切都成功,但在 make run 期间我遇到了很多错误。目前我在 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 link获取完整的源代码。我将不胜感激任何建议和帮助,谢谢

最佳答案

问题似乎是 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

关于python - 即使我安装了软件包,在 makefile 上构建 python 软件包时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58637239/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com