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然后就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arnold-FY-Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值