很想一行指令pip install pycocotools 搞定,雖然失敗,但實用方法如下:
1、問題描述和定位:在Windows環境下遇到:ModuleNotFoundError: No module named 'pycocotools'錯誤提示,說明需要安裝工具包pycocotools,以下介紹具體安裝方法。
2、具體解決方法
1)從 https://github.com/pdollar/coco.git這個網址下載源碼,并將此解壓到完全英文的路徑下。
2)在cocoapi-master/PythonAPI文件夾下,打開Powershell窗口(快捷方式:shift+鼠標右鍵),運行命令:python setup.py build_ext --inplace進行編譯。
若編譯出現錯誤: cl: 命令行 error D8021 :無效的數值參數“/Wno-cpp” error: command 'D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe' failed with exit status 2。需要當前文件夾下的setup.py文件,直接將其中的語句extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99']修改為extra_compile_args=[ '-std=c99']。并重新運行命令:python setup.py build_ext --inplace
3)上一步沒有問題則繼續在Powershell窗口運行命令:python setup.py build_ext install完成安裝即可。
轉載自:
作者:鄭州菩提
鏈接:http://www.lxweimin.com/p/74c70de6ee24
來源:簡書