Ubuntu非conda环境python3.8下安装labelme

news/2025/2/25 13:41:13

很久没用过labelme了,造实验数据需要在一个没有conda的Ubuntu20.04安装了python3.8.10的环境下安装labelme,先是直接执行

  pip install labelme

执行了多次每次都是卡死,后来先执行pip install pyqt发现也是卡死在同样的地方,发现原来是安装PyQt 5.15.11时有个提示要求输入yes来确认license,但是输入后回车没有任何反映,按CTRL+C报类似下面的错误:

  Getting requirements to build wheel ... done
    Created temporary directory: /tmp/pip-modern-metadata-2m8up4ly
    Running command /usr/bin/python3 /tmp/tmp5__09fv9 prepare_metadata_for_build_wheel /tmp/tmplm26exwn
    Querying qmake about your Qt installation...
    This is the GPL version of PyQt 5.15.11 (licensed under the GNU General Public License) for Python 3.8.10 on linux.

    Type 'L' to view the license.
    Type 'yes' to accept the terms of the license.
    Type 'no' to decline the terms of the license.

L
^C^C    Preparing wheel metadata ... canceled
Cleaning up...
  Removing source in /tmp/pip-install-de6yndpt/labelme
  Removing source in /tmp/pip-install-de6yndpt/PyQt5
Removed PyQt5!=5.15.3,!=5.15.4 from https://files.pythonhosted.org/packages/0e/07/c9ed0bd428df6f87183fca565a79fee19fa7c88c7f00a7f011ab4379e77a/PyQt5-5.15.11.tar.gz#sha256=fda45743ebb4a27b4b1a51c6d8ef455c4c1b5d610c90d2934c7802b5c1557c52 (from labelme) from build tracker '/tmp/pip-req-tracker-ptuu_f15'
Removed build tracker: '/tmp/pip-req-tracker-ptuu_f15'
ERROR: Operation cancelled by user
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 515, in prepare_linked_requirement
    abstract_dist = _get_prepared_distribution(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 40, in prepare_distribution_metadata
    self.req.prepare_metadata()
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 564, in prepare_metadata
    self.metadata_directory = self._generate_metadata()
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 549, in _generate_metadata
    return generate_metadata(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/build/metadata.py", line 36, in generate_metadata
    distinfo_dir = backend.prepare_metadata_for_build_wheel(
  File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 176, in prepare_metadata_for_build_wheel
    return self._call_hook('prepare_metadata_for_build_wheel', {
  File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 255, in _call_hook
    self._subprocess_runner(
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runner
    call_subprocess(
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 202, in call_subprocess
    line = console_to_str(proc.stdout.readline())
KeyboardInterrupt

有时错误是这样的:

  Successfully installed PyQt-builder-1.18.0 packaging-24.2 setuptools-75.3.0 sip-6.8.6 tomli-2.2.1
  Cleaning up...
  Removed build tracker: '/tmp/pip-req-tracker-016_2t0l'
  Installing build dependencies ... done
  Running command /usr/bin/python3 /tmp/tmpduzujhqo get_requires_for_build_wheel /tmp/tmpf6cr3v28
  Getting requirements to build wheel ... done
    Created temporary directory: /tmp/pip-modern-metadata-455t07eg
    Running command /usr/bin/python3 /tmp/tmpb4id76s0 prepare_metadata_for_build_wheel /tmp/tmpbzom7kfd
    Querying qmake about your Qt installation...
    This is the GPL version of PyQt 5.15.11 (licensed under the GNU General Public License) for Python 3.8.10 on linux.

    Type 'L' to view the license.
    Type 'yes' to accept the terms of the license.
    Type 'no' to decline the terms of the license.

L
yes
^C^C    Preparing wheel metadata ... Cleaning up...
  Removing source in /tmp/pip-install-dwxenbiv/pyqt5
Removed pyqt5 from https://files.pythonhosted.org/packages/0e/07/c9ed0bd428df6f87183fca565a79fee19fa7c88c7f00a7f011ab4379e77a/PyQt5-5.15.11.tar.gz#sha256=fda45743ebb4a27b4b1a51c6d8ef455c4c1b5d610c90d2934c7802b5c1557c52 from build tracker '/tmp/pip-req-tracker-016_2t0l'
Removed build tracker: '/tmp/pip-req-tracker-016_2t0l'
ERROR: Operation cancelled by user
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runner
    call_subprocess(
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 202, in call_subprocess
    line = console_to_str(proc.stdout.readline())
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
    resolver.resolve(requirement_set)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 282, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 515, in prepare_linked_requirement
    abstract_dist = _get_prepared_distribution(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 40, in prepare_distribution_metadata
    self.req.prepare_metadata()
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 564, in prepare_metadata
    self.metadata_directory = self._generate_metadata()
  File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 549, in _generate_metadata
    return generate_metadata(
  File "/usr/lib/python3/dist-packages/pip/_internal/operations/build/metadata.py", line 36, in generate_metadata
    distinfo_dir = backend.prepare_metadata_for_build_wheel(
  File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 176, in prepare_metadata_for_build_wheel
    return self._call_hook('prepare_metadata_for_build_wheel', {
  File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 255, in _call_hook
    self._subprocess_runner(
  File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runner
    call_subprocess(
KeyboardInterrupt

归根结底是卡在

File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 202, in call_subprocess
    line = console_to_str(proc.stdout.readline())

开始以为是需要conda的支持,到一个conda环境里也这么安装发现也是卡在这里,那就跟有没有conda没关系,于是猜测和PyQt的版本有关系,换个低一点版本可能可以,于是执行

                      pip install  pyqt5==5.13.0

改安装5.13.0果然顺利安装成功了,再执行

                      pip install labelme

也安装成功了

conda环境下,可以直接执行labelme,因为自动把labelme文件加到了conda/bin里了,在没有conda的环境下,需要自己设置一下PATH环境变量。

首先执行一下

        sudo find / -path /media  -prune -o -name labelme

找到labelme文件在哪里(-path和-prune 是排除掉不需要搜索的目录路径),发现了是在~/.local/bin下,于是把这个路径加到PATH里去并source一下让设置生效

  export PATH=$PATH:~/.local/bin/labelme

 然后执行labelme,报新的错误:    

Traceback (most recent call last):
  File "/home/andong/.local/bin/labelme", line 5, in <module>
    from labelme.__main__ import main
  File "/home/andong/.local/lib/python3.8/site-packages/labelme/__main__.py", line 14, in <module>
    from labelme.app import MainWindow
  File "/home/andong/.local/lib/python3.8/site-packages/labelme/app.py", line 22, in <module>
    from labelme import ai
  File "/home/andong/.local/lib/python3.8/site-packages/labelme/ai/__init__.py", line 5, in <module>
    from .text_to_annotation import get_rectangles_from_texts  # NOQA: F401
  File "/home/andong/.local/lib/python3.8/site-packages/labelme/ai/text_to_annotation.py", line 10, in <module>
    model: str, image: np.ndarray, texts: list[str]
TypeError: 'type' object is not subscriptable

这是python3.8不再支持类似 list[str]和tuple[np.ndarray, np.ndarray, np.ndarray]这样的写法,需要使用typing.List和typing.Tuple类来替代,所以text_to_annotation.py文件里需要修改三处:

def get_rectangles_from_texts(
    model: str, image: np.ndarray, texts: List[str]
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
#    model: str, image: np.ndarray, texts: list[str]
#) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
    request: osam.types.GenerateRequest = osam.types.GenerateRequest(
        model=model,
        image=image,
        prompt=osam.types.Prompt(
            texts=texts,
            iou_threshold=1.0,
            score_threshold=0.01,
            max_annotations=1000,
        ),
    )
def non_maximum_suppression(
    boxes: np.ndarray,
    scores: np.ndarray,
    labels: np.ndarray,
    iou_threshold: float,
    score_threshold: float,
    max_num_detections: int,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
#) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
    num_classes = np.max(labels) + 1
def get_shapes_from_annotations(
    boxes: np.ndarray, scores: np.ndarray, labels: np.ndarray, texts: List[str]
) -> List[dict]:
    shapes: List[dict] = []
#    boxes: np.ndarray, scores: np.ndarray, labels: np.ndarray, texts: list[str]
#) -> list[dict]:
#    shapes: list[dict] = []
    for box, score, label in zip(boxes.tolist(), scores.tolist(), labels.tolist()):
        text = texts[label]
        xmin, ymin, xmax, ymax = box
        shape = {
            "label": text,
            "points": [[xmin, ymin], [xmax, ymax]],
            "group_id": None,
            "shape_type": "rectangle",
            "flags": {},
            "description": json.dumps(dict(score=score, text=text)),
        }
        shapes.append(shape)
    return shapes

然后执行labelme,就成功起来了:

 不过在我的conda环境里还报了一个错误:

Traceback (most recent call last):
  File "/root/anaconda3/envs/lstr/bin/labelme", line 5, in <module>
    from labelme.__main__ import main
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/__main__.py", line 14, in <module>
    from labelme.app import MainWindow
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/app.py", line 27, in <module>
    from labelme.shape import Shape
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/shape.py", line 4, in <module>
    import skimage.measure
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/measure/__init__.py", line 6, in <module>
    from .simple_metrics import compare_mse, compare_nrmse, compare_psnr
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/measure/simple_metrics.py", line 2, in <module>
    from ..metrics.simple_metrics import (mean_squared_error,
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/metrics/__init__.py", line 1, in <module>
    from ._adapted_rand_error import adapted_rand_error
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/metrics/_adapted_rand_error.py", line 2, in <module>
    from ._contingency_table import contingency_table
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/metrics/_contingency_table.py", line 1, in <module>
    import scipy.sparse as sparse
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/scipy/sparse/__init__.py", line 229, in <module>
    from .base import *
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/scipy/sparse/base.py", line 8, in <module>
    from .sputils import (isdense, isscalarlike, isintlike,
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/scipy/sparse/sputils.py", line 17, in <module>
    supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/scipy/sparse/sputils.py", line 17, in <listcomp>
    supported_dtypes = [np.typeDict[x] for x in supported_dtypes]
  File "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/numpy/__init__.py", line 320, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'typeDict'

一般这个错误是因为numpy版本不对,查看了一下conda环境里Numpy版本是1.24.4,但是我能正常运行labelme的非conda环境里的Numpy的版本也是1.24.4,真是莫名其妙,没时间查原因,反正先把版本降低到1.21然后就可以了


http://www.niftyadmin.cn/n/5865561.html

相关文章

即将发布书籍 - Yocto项目实战教程:高效定制嵌入式Linux系统

以下这本书《Yocto项目实战教程&#xff1a;高效定制嵌入式Linux系统》即将发布&#xff0c;现在请哪位大佬出山写一个序或者推荐&#xff0c;有兴趣的大佬&#xff0c;请联系我&#xff01; Git仓库地址&#xff1a; https://github.com/jerrysundev/Yocto-Project-Book.git …

一篇文章学懂Vuex

一、基于VueCli自定义创建项目 233 344 二、Vuex 初始准备 建项目的时候把vuex勾选上就不用再yarn add vuex3了 store/index.js // 这里面存放的就是vuex相关的核心代码 import Vuex from vuex import Vue from vue// 插件安装 Vue.use(Vuex)// 创建仓库&#xff08;空仓库…

PyVideoTrans:一款功能全面的视频翻译配音工具!

PyVideoTrans是一款功能全面的视频翻译配音工具&#xff0c;专为视频内容创作者设计。它能够将视频中的语言翻译成另一种语言&#xff0c;并自动生成与之匹配的字幕和配音。支持多种语言&#xff0c;包括但不限于中文&#xff08;简繁体&#xff09;、英语、韩语、日语、俄语、…

MySQL数据库连接池泄露导致MySQL Server超时关闭连接

前言 最近做项目&#xff0c;发现老项目出现xxx&#xff0c;这个错误其实很简单&#xff0c;出现在MySQL数据库Server端对长时间没有使用的client连接执行清楚处理&#xff0c;因为是druid数据库&#xff0c;且在github也出现这样的issue&#xff1a;The last packet successf…

拓扑排序的核心算法:BFS应用与实践

目录 一、拓扑排序简介 二、BFS解决拓扑排序的步骤 三、C实现 四、代码解释 五、总结 一、拓扑排序简介 拓扑排序是对有向无环图&#xff08;DAG&#xff09;进行排序的一种方法&#xff0c;使得对于图中的每一条有向边 (u, v)&#xff0c;u 在排序中总是位于 v 的前面。拓…

AIGC-LLAMA模型介绍

LLAMA模型介绍 LLAMA模型介绍LLAMA模型架构模型特点 训练数据代码示例 LLAMA模型介绍 LLAMA&#xff08;LLaMA, Large Language Model Meta AI&#xff09;是Meta&#xff08;前Facebook&#xff09;开发的一系列大型语言模型。LLAMA模型家族旨在提供高效、灵活的语言处理能力…

Java Web框架篇之Spring

Java Web系列文章汇总贴: Java Web知识总结汇总 为什么要有Spring(IoC) Web发展的几个阶段 &#xff08;1&#xff09;初级阶段&#xff1a;使用Model1(JSPJavaBean)/Model2(JspServletJavaBean)/三层模型(表示层(JSP/Servlet)业务逻辑层持久化层)进行开发&#xff1b;&#…

服务器租用的价格受哪些因素影响?

1、 服务器配置 租用服务器配置的成本占租用服务器成本的关键部分。如果服务器配置完善、功能完善、臭名昭著&#xff0c;那么租赁价格肯定会高于所有其他级别的普通服务器。 2、 服务器防御 租用服务器的成本与其安全保护能力成正比。例如&#xff0c;移动游戏和金融易受DDoS和…