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

问题描述 投票:0回答:1

我正在尝试为某个项目运行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 link以获取完整的源代码。我将不胜感激任何建议,并感谢您]

python makefile mypy
1个回答
0
投票

问题似乎使我无法找到模块。运行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

© www.soinside.com 2019 - 2024. All rights reserved.