当前位置: 首页 > article >正文

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

很久没用过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.kler.cn/a/560090.html

相关文章:

  • Vue全局变量的定义和使用,创建 Store变量、读取、修改
  • Django数据库操作
  • 最长递增子序列(贪心算法)思路+源码
  • zookeeper从入门到精通
  • 在CentOS7上部署与关闭Flask接口
  • GoFly框架中集成Bolt 和badfer两个Go语言嵌入式键值数据库
  • 2025.2.24总结
  • 【java】重载(overloading)和重写(overriding)
  • 单片机分层架构的头文件设计
  • springboot集成jackson-dataformat-xml实现发送XML请求和XML响应参数处理
  • 商业银行预算管理系统的架构、流程、原型
  • 一周学会Flask3 Python Web开发-flask3上下文全局变量session,g和current_app
  • JAVA+MySQL实现分库分表及设计思路
  • 分享一个免费的CKA认证学习资料
  • 3. Spring Cloud LoadBalancer 入门与使用
  • 【OpenCV】入门教学
  • Websocket、WebRTC在大模型中的应用
  • 机器学习数学基础:36.φ相关系数分析
  • steam_api.dll丢失3分钟修复指南,解决Steam游戏无法运行
  • Idea2024中搭建JavaFX开发环境并创建运行项目