支持 Windows 的 COCO 地址:https://github.com/philferriere/cocoapi
安裝方案1:在線安裝【我沒有成功,所以我用的是方案2離線安裝】
A:安裝git
conda install git
B:安裝python對應版本的C++編譯器
這一步非常重要,我放在後面再說。
C:pip安裝cocoapi
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
安裝方案2:離線安裝【我自己是成功了】
A:下載
到 https://github.com/philferriere/cocoapi 頁面下載源碼包
B:解壓
C:進入到需要編譯的目錄PythonAPI
D:安裝python版本對應的C++編譯器【★至關重要,成功關鍵★】
1):查看自己需要的編譯器版本
在剛纔的文件夾底下,同時按住shift鍵+鼠標右鍵,選擇在此處打開命令窗口
在彈出的cmd窗口中輸入python,紅色框是python版本3.7.0,綠色框是需要的C++編譯器版本1912
2):根據編譯器版本查找VS版本
https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
3):下載對應的VS版本【沒有就下載高一個小版本的VS】
注意:csdn上有好多Microsoft Visual C++ Build Tools 2017 這種資源,千萬不要下載,大都是VS15,小版本都不對,浪費時間精力和積分。
我這邊以VS2017(15.7爲例),直接去msdn i tell you去下載,安裝的時候,只要安裝C++的就行,同時勾選Windows 10 SDK.
安裝完重啓一下電腦。
4):開始安裝,cmd中輸入
# install pycocotools locally
python setup.py build_ext --inplace
# install pycocotools to the Python site-packages
python setup.py build_ext install
錯誤1:pyconfig.h(59) fatal error C1083: Cannot open include file: 'io.h': No such file
參考:https://stackoverflow.com/questions/40018405/cannot-open-include-file-io-h-no-such-file-or-directory
解決:
A:在 C:\Program Files (x86)\Windows Kits\10 中搜索io.h
B:將找到的路徑,在cmd中輸入
set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt
同樣的錯誤可能還會遇到,解決方案一樣,缺少頭文件,就設置 set INCLUDE,缺少lib文件,就設置 set LIB.
我安裝時候,提示缺少 io.h, basetsd.h兩個頭文件【多個的時候,用分號隔開】
set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\shared
提示缺少 ucrt.lib, kernel32.Lib兩個lib文件
set LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64
C:運行
# install pycocotools locally
python setup.py build_ext --inplace
# install pycocotools to the Python site-packages
python setup.py build_ext install
錯誤2:解決了問題1,可能還會在鏈接的時候遇到 LINK : fatal error LNK1158: “rc.exe
參考:https://stackoverflow.com/questions/43847542/rc-exe-no-longer-found-in-vs-2015-command-prompt/45319119#45319119裏面有各種各樣的解決方案,可以看一下哪個適合自己
解決:
A:將小版本下的 rc.exe and rc.dll 兩個文件拷貝到對應文件夾下面[x64和x86的我都對應拷貝了]
c:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64
c:\Program Files (x86)\Windows Kits\10\bin\x64
c:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86
c:\Program Files (x86)\Windows Kits\10\bin\x86
B:將上面的路徑添加到系統環境變量
右鍵我的電腦【計算機】--屬性--高級系統設置--高級--環境變量--系統變量
找到path,雙擊打開,將上面的路徑粘貼進去,分號隔開
C:關掉之前的cmd窗口,重新走一遍錯誤1的解決方案ABC,就可以順利通過編譯了
(๑•ᴗ•๑)覺得有用,賞個植髮的小錢錢。(๑•ᴗ•๑)