You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装Mask2Former后仍出现ModuleNotFoundError问题求助

Mask2Former导入报错ModuleNotFoundError的解决

问题详情

按照detectron2官方安装文档安装Mask2Former,已确认detectron2安装成功。执行的安装命令:

git clone git@github.com:facebookresearch/Mask2Former.git
cd Mask2Former
pip install -r requirements.txt
cd mask2former/modeling/pixel_decoder/ops
sh make.sh

安装日志末尾显示MultiScaleDeformableAttention 1.0已成功安装:

Installed /home/lab-602/anaconda3/envs/mask2former/lib/python3.9/site-packages/MultiScaleDeformableAttention-1.0-py3.9-linux-x86_64.egg
Processing dependencies for MultiScaleDeformableAttention==1.0
Finished processing dependencies for MultiScaleDeformableAttention==1.0

但尝试导入mask2former时,报错ModuleNotFoundError: No module named 'mask2former'。

环境信息:

Python 3.9.19
CUDA 12.5
absl-py                       2.1.0
antlr4-python3-runtime        4.9.3
black                         24.4.2
certifi                       2024.7.4
charset-normalizer            3.3.2
click                         8.1.7
cloudpickle                   3.0.0
contourpy                     1.2.1
cycler                        0.12.1
Cython                        3.0.10
detectron2                    0.6                /home/lab-602/detectron2
filelock                      3.15.4
fonttools                     4.53.1
fsspec                        2024.6.1
fvcore                        0.1.5.post20221221
grpcio                        1.65.1
h5py                          3.11.0
huggingface-hub               0.24.0
hydra-core                    1.3.2
idna                          3.7
imageio                       2.34.2
importlib_metadata            8.0.0
importlib_resources           6.4.0
iopath                        0.1.9
Jinja2                        3.1.4
kiwisolver                    1.4.5
lazy_loader                   0.4
Markdown                      3.6
MarkupSafe                    2.1.5
matplotlib                    3.9.1
mpmath                        1.3.0
MultiScaleDeformableAttention 1.0
mypy-extensions               1.0.0
networkx                      3.2.1
ninja                         1.11.1.1
numpy                         2.0.0
nvidia-cublas-cu12            12.1.3.1
nvidia-cuda-cupti-cu12        12.1.105
nvidia-cuda-nvrtc-cu12        12.1.105
nvidia-cuda-runtime-cu12      12.1.105
nvidia-cudnn-cu12             8.9.2.26
nvidia-cufft-cu12             11.0.2.54
nvidia-curand-cu12            10.3.2.106
nvidia-cusolver-cu12          11.4.5.107
nvidia-cusparse-cu12          12.1.0.106
nvidia-nccl-cu12              2.20.5
nvidia-nvjitlink-cu12         12.5.82
nvidia-nvtx-cu12              12.1.105
omegaconf                     2.3.0
opencv-python                 4.10.0.84
packaging                     24.1
pathspec                      0.12.1
pillow                        10.4.0
pip                           24.0
platformdirs                  4.2.2
portalocker                   2.10.1
protobuf                      4.25.3
pycocotools                   2.0.8
pyparsing                     3.1.2
python-dateutil               2.9.0.post0
PyYAML                        6.0.1
requests                      2.32.3
safetensors                   0.4.3
scikit-image                  0.24.0
scipy                         1.13.1
setuptools                    69.5.1
shapely                       2.0.5
six                           1.16.0
submitit                      1.5.1
sympy                         1.13.0
tabulate                      0.9.0
tensorboard                   2.17.0
tensorboard-data-server       0.7.2
termcolor                     2.4.0
tifffile                      2024.7.2
timm                          1.0.7
tomli                         2.0.1
torch                         2.3.1
torchaudio                    2.3.1
torchvision                   0.18.1
tqdm                          4.66.4
triton                        2.3.1
typing_extensions             4.12.2
urllib3                       2.2.2
Werkzeug                      3.0.3
wheel                         0.43.0
yacs                          0.1.8
zipp                          3.19.2

解决步骤

  • 回到Mask2Former项目根目录,执行以下命令将包以可编辑模式安装到当前环境:
    pip install -e .
    
    这会让Python识别到mask2former模块。
  • 若不想安装包,可直接将项目根目录添加到Python环境变量:
    export PYTHONPATH=/home/lab-602/Mask2Former:$PYTHONPATH
    
    若使用conda环境,可将该命令写入环境的activate.d脚本,实现自动加载。
  • 检查当前Python和pip路径是否对应目标环境,执行which python和which pip确认路径与安装时的环境一致。

内容的提问来源于stack exchange,提问作者浮闇居

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 21:14:55