mamba-ssm的安装报错解决
在配置SCSegamba的环境时出现报错,很多用了mamba的模型如果也报了错,应该都可以用这个方法来解决。
conda create -n SCSegamba python=3.10 -y conda activate SCSegamba pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 -f https://download.pytorch.org/whl/torch_stable.html pip install -U openmim mim install mmcv-full pip install mamba-ssm==1.2.0 pip install timm lmdb mmengine numpy
执行到安装mamba-ssm时,首先报了下面这种错,报错上说No module named 'torch',可是我之前明明已经装好了torch。
Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting mamba-ssm==1.2.0 Downloading https://mirrors.aliyun.com/pypi/packages/b5/65/f648f2ac2e783858810f802856037e9600425673a48326273c68631b9b4c/mamba_ssm-1.2.0.tar.gz (34 kB) Installing build dependencies ... done Getting requirements to build wheel ... error error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. │ exit code: 1 ╰─> [19 lines of output] /tmp/pip-build-env-d0i5jc3p/overlay/lib/python3.10/site-packages/setuptools/_vendor/wheel/bdist_wheel.py:4: FutureWarning: The 'wheel' package is no longer the canonical location of the 'bdist_wheel' command, and will be removed in a future release. Please update to setuptools v70.1 or later which contains an integrated version of this command. warn( Traceback (most recent call last): File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel return hook(config_settings) File "/tmp/pip-build-env-d0i5jc3p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 333, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=[]) File "/tmp/pip-build-env-d0i5jc3p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires self.run_setup() File "/tmp/pip-build-env-d0i5jc3p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 520, in run_setup super().run_setup(setup_script=setup_script) File "/tmp/pip-build-env-d0i5jc3p/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 19, in <module> ModuleNotFoundError: No module named 'torch' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed to build 'mamba-ssm' when getting requirements to build wheel
经过调查发现,其实这里有一个很奇怪的机制,pip 构建 mamba-ssm 时会临时起一个 /tmp/pip-build-env-... 的干净环境去跑 setup.py/pyproject,那个临时环境里没有 torch,所以炸了。
目前还不明白是哪里导致发生这么奇怪的机制的。
在安装时关闭 build isolation,执行下面的命令,就可以正常安装了。
pip install mamba-ssm==1.2.0 --no-build-isolation
另外安装mamba-ssm时有可能还会报下面这样的奇怪的错,这个错又说No module named 'pkg_resources',更新了setuptools后重新安装也不起作用,最后发现是需要重新安装指定setuptools的版本后,才能解决报错,很怪。。。。
我指定的版本是setuptools==79.0.1
Looking in indexes: https://mirrors.aliyun.com/pypi/simple Collecting mamba-ssm==1.2.0 Using cached https://mirrors.aliyun.com/pypi/packages/b5/65/f648f2ac2e783858810f802856037e9600425673a48326273c68631b9b4c/mamba_ssm-1.2.0.tar.gz (34 kB) Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [19 lines of output] /hy-tmp/SCSegamba/lib/python3.10/site-packages/wheel/bdist_wheel.py:4: FutureWarning: The 'wheel' package is no longer the canonical location of the 'bdist_wheel' command, and will be removed in a future release. Please update to setuptools v70.1 or later which contains an integrated version of this command. warn( Traceback (most recent call last): File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module> main() File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main json_out["return_val"] = hook(**hook_input["kwargs"]) File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 175, in prepare_metadata_for_build_wheel return hook(metadata_directory, config_settings) File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/setuptools/build_meta.py", line 380, in prepare_metadata_for_build_wheel self.run_setup() File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/setuptools/build_meta.py", line 520, in run_setup super().run_setup(setup_script=setup_script) File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup exec(code, locals()) File "<string>", line 20, in <module> File "/hy-tmp/SCSegamba/lib/python3.10/site-packages/torch/utils/cpp_extension.py", line 25, in <module> from pkg_resources import packaging # type: ignore[attr-defined] ModuleNotFoundError: No module named 'pkg_resources' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> mamba-ssm note: This is an issue with the package mentioned above, not pip. hint: See above for details.
浙公网安备 33010602011771号