很久没用过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 ... doneCreated temporary directory: /tmp/pip-modern-metadata-2m8up4lyRunning command /usr/bin/python3 /tmp/tmp5__09fv9 prepare_metadata_for_build_wheel /tmp/tmplm26exwnQuerying 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/labelmeRemoving 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 _mainstatus = self.run(options, args)File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in runresolver.resolve(requirement_set)File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolvediscovered_reqs.extend(self._resolve_one(requirement_set, req))File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_oneabstract_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_forabstract_dist = self.preparer.prepare_linked_requirement(req)File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 515, in prepare_linked_requirementabstract_dist = _get_prepared_distribution(File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distributionabstract_dist.prepare_distribution_metadata(finder, build_isolation)File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 40, in prepare_distribution_metadataself.req.prepare_metadata()File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 564, in prepare_metadataself.metadata_directory = self._generate_metadata()File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 549, in _generate_metadatareturn generate_metadata(File "/usr/lib/python3/dist-packages/pip/_internal/operations/build/metadata.py", line 36, in generate_metadatadistinfo_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_wheelreturn 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_hookself._subprocess_runner(File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runnercall_subprocess(File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 202, in call_subprocessline = 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.1Cleaning up...Removed build tracker: '/tmp/pip-req-tracker-016_2t0l'Installing build dependencies ... doneRunning command /usr/bin/python3 /tmp/tmpduzujhqo get_requires_for_build_wheel /tmp/tmpf6cr3v28Getting requirements to build wheel ... doneCreated temporary directory: /tmp/pip-modern-metadata-455t07egRunning command /usr/bin/python3 /tmp/tmpb4id76s0 prepare_metadata_for_build_wheel /tmp/tmpbzom7kfdQuerying 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 runnercall_subprocess(File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 202, in call_subprocessline = console_to_str(proc.stdout.readline())
KeyboardInterruptDuring 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 _mainstatus = self.run(options, args)File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in runresolver.resolve(requirement_set)File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolvediscovered_reqs.extend(self._resolve_one(requirement_set, req))File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_oneabstract_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_forabstract_dist = self.preparer.prepare_linked_requirement(req)File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 515, in prepare_linked_requirementabstract_dist = _get_prepared_distribution(File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 95, in _get_prepared_distributionabstract_dist.prepare_distribution_metadata(finder, build_isolation)File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 40, in prepare_distribution_metadataself.req.prepare_metadata()File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 564, in prepare_metadataself.metadata_directory = self._generate_metadata()File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 549, in _generate_metadatareturn generate_metadata(File "/usr/lib/python3/dist-packages/pip/_internal/operations/build/metadata.py", line 36, in generate_metadatadistinfo_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_wheelreturn 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_hookself._subprocess_runner(File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 271, in runnercall_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 mainFile "/home/andong/.local/lib/python3.8/site-packages/labelme/__main__.py", line 14, in <module>from labelme.app import MainWindowFile "/home/andong/.local/lib/python3.8/site-packages/labelme/app.py", line 22, in <module>from labelme import aiFile "/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: F401File "/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 = boxshape = {"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 mainFile "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/__main__.py", line 14, in <module>from labelme.app import MainWindowFile "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/app.py", line 27, in <module>from labelme.shape import ShapeFile "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/labelme/shape.py", line 4, in <module>import skimage.measureFile "/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_psnrFile "/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_errorFile "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/metrics/_adapted_rand_error.py", line 2, in <module>from ._contingency_table import contingency_tableFile "/root/anaconda3/envs/lstr/lib/python3.8/site-packages/skimage/metrics/_contingency_table.py", line 1, in <module>import scipy.sparse as sparseFile "/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然后就可以了