win10安装pycocotools遇到的问题

背景安装pycocotools一直过不去,一直报错

PS C:\Users\peter> pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
  Cloning https://github.com/philferriere/cocoapi.git to c:\users\peter\appdata\local\temp\pip-req-build-_9qbjwiy
Building wheels for collected packages: pycocotools
  Running setup.py bdist_wheel for pycocotools ... error
  Complete output from command d:\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\peter\\AppData\\Local\\Temp\\pip-req-build-_9qbjwiy\\PythonAPI\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\peter\AppData\Local\Temp\pip-wheel-ccfig2_s --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.6
  creating build\lib.win-amd64-3.6\pycocotools
  copying pycocotools\coco.py -> build\lib.win-amd64-3.6\pycocotools
  copying pycocotools\cocoeval.py -> build\lib.win-amd64-3.6\pycocotools
  copying pycocotools\mask.py -> build\lib.win-amd64-3.6\pycocotools
  copying pycocotools\__init__.py -> build\lib.win-amd64-3.6\pycocotools
  running build_ext
  building 'pycocotools._mask' extension
  creating build\temp.win-amd64-3.6
  creating build\temp.win-amd64-3.6\Release
  creating build\temp.win-amd64-3.6\Release\pycocotools
  creating build\temp.win-amd64-3.6\common
  D:\Anaconda3\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -Id:\anaconda3\lib\site-packages\numpy\core\include -I../common -Id:\anaconda3\include -Id:\anaconda3\include -c pycocotools/_mask.c -o build\temp.win-amd64-3.6\Release\pycocotools\_mask.o
  In file included from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:1816:0,
                   from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18,
                   from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
                   from pycocotools/_mask.c:590:
  d:\anaconda3\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h:12:9: note: #pragma message: d:\anaconda3\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
  pycocotools/_mask.c: In function '__Pyx_ImportType':
  pycocotools/_mask.c:16964:13: warning: unknown conversion type character 'z' in format [-Wformat]
  pycocotools/_mask.c:16964:13: warning: unknown conversion type character 'z' in format [-Wformat]
  pycocotools/_mask.c:16964:13: warning: too many arguments for format [-Wformat-extra-args]
  D:\Anaconda3\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -Id:\anaconda3\lib\site-packages\numpy\core\include -I../common -Id:\anaconda3\include -Id:\anaconda3\include -c ../common/maskApi.c -o build\temp.win-amd64-3.6\Release\..\common\maskapi.o
  writing build\temp.win-amd64-3.6\Release\pycocotools\_mask.cp36-win_amd64.def
  D:\Anaconda3\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-3.6\Release\pycocotools\_mask.o build\temp.win-amd64-3.6\Release\..\common\maskapi.o build\temp.win-amd64-3.6\Release\pycocotools\_mask.cp36-win_amd64.def -Ld:\anaconda3\libs -Ld:\anaconda3\PCbuild\amd64 -lpython36 -lmsvcr140 -o build\lib.win-amd64-3.6\pycocotools\_mask.cp36-win_amd64.pyd
  d:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\temp.win-amd64-3.6\Release\pycocotools\_mask.cp36-win_amd64.def:1: syntax error
  d:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe:build\temp.win-amd64-3.6\Release\pycocotools\_mask.cp36-win_amd64.def: file format not recognized; treating as linker script
  d:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld.exe:build\temp.win-amd64-3.6\Release\pycocotools\_mask.cp36-win_amd64.def:1: syntax error
  collect2.exe: error: ld returned 1 exit status
  error: command 'D:\\Anaconda3\\MinGW\\bin\\gcc.exe' failed with exit status 1

Failed building wheel for pycocotools
Running setup.py clean for pycocotools
Complete output from command d:\anaconda3\python.exe -u -c “import setuptools, tokenize;file=‘C:\Users\peter\AppData\Local\Temp\pip-req-build-_9qbjwiy\PythonAPI\setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” clean --all:
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “C:\Users\peter\AppData\Local\Temp\pip-req-build-_9qbjwiy\PythonAPI\setup.py”, line 25, in <module>
cythonize(ext_modules)
File “d:\anaconda3\lib\site-packages\Cython\Build\Dependencies.py”, line 897, in cythonize
aliases=aliases)
File “d:\anaconda3\lib\site-packages\Cython\Build\Dependencies.py”, line 777, in create_extension_list
for file in nonempty(sorted(extended_iglob(filepattern)), “’%s’ doesn’t match any files” % filepattern):
File “d:\anaconda3\lib\site-packages\Cython\Build\Dependencies.py”, line 102, in nonempty
raise ValueError(error_msg)
ValueError: ‘pycocotools/_mask.pyx’ doesn’t match any files


Failed cleaning build dir for pycocotools
Failed to build pycocotools
Installing collected packages: pycocotools
Running setup.py install for pycocotools … error
Complete output from command d:\anaconda3\python.exe -u -c “import setuptools, tokenize;file=‘C:\Users\peter\AppData\Local\Temp\pip-req-build-_9qbjwiy\PythonAPI\setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record C:\Users\peter\AppData\Local\Temp\pip-record-kjy7gqmp\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
running build_ext
building ‘pycocotools._mask’ extension
D:\Anaconda3\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -Id:\anaconda3\lib\site-packages\numpy\core\include -I…/common -Id:\anaconda3\include -Id:\anaconda3\include -c pycocotools/_mask.c -o build\temp.win-amd64-3.6\Release\pycocotools_mask.o
In file included from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/ndarraytypes.h:1816:0,
from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/ndarrayobject.h:18,
from d:\anaconda3\lib\site-packages\numpy\core\include/numpy/arrayobject.h:4,
from pycocotools/_mask.c:590:
d:\anaconda3\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h:12:9: note: #pragma message: d:\anaconda3\lib\site-packages\numpy\core\include/numpy/npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pycocotools/_mask.c: In function ‘__Pyx_ImportType’:
pycocotools/_mask.c:16964:13: warning: unknown conversion type character ‘z’ in format [-Wformat]
pycocotools/_mask.c:16964:13: warning: unknown conversion type character ‘z’ in format [-Wformat]
pycocotools/_mask.c:16964:13: warning: too many arguments for format [-Wformat-extra-args]
D:\Anaconda3\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -Id:\anaconda3\lib\site-packages\numpy\core\include -I…/common -Id:\anaconda3\include -Id:\anaconda3\include -c …/common/maskApi.c -o build\temp.win-amd64-3.6\Release…\common\maskapi.o
writing build\temp.win-amd64-3.6\Release\pycocotools_mask.cp36-win_amd64.def
D:\Anaconda3\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-3.6\Release\pycocotools_mask.o build\temp.win-amd64-3.6\Release…\common\maskapi.o build\temp.win-amd64-3.6\Release\pycocotools_mask.cp36-win_amd64.def -Ld:\anaconda3\libs -Ld:\anaconda3\PCbuild\amd64 -lpython36 -lmsvcr140 -o build\lib.win-amd64-3.6\pycocotools_mask.cp36-win_amd64.pyd
d:/anaconda3/mingw/bin/…/lib/gcc/x86_64-w64-mingw32/4.7.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: build\temp.win-amd64-3.6\Release\pycocotools_mask.cp36-win_amd64.def:1: syntax error
d:/anaconda3/mingw/bin/…/lib/gcc/x86_64-w64-mingw32/4.7.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe:build\temp.win-amd64-3.6\Release\pycocotools_mask.cp36-win_amd64.def: file format not recognized; treating as linker script
d:/anaconda3/mingw/bin/…/lib/gcc/x86_64-w64-mingw32/4.7.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe:build\temp.win-amd64-3.6\Release\pycocotools_mask.cp36-win_amd64.def:1: syntax error
collect2.exe: error: ld returned 1 exit status
error: command ‘D:\Anaconda3\MinGW\bin\gcc.exe’ failed with exit status 1

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86

解决方法

原因是编译安装时python用的mingw32的gcc而不是用msvc,因此一直有些问题

solution

  1. 进入python安装目录(anaconda目录),找到Lib,进入
  2. 找到distutils包,进入找到distutils.cfg文件
    用anaconda的话是这样的
[build]           
compiler=mingw32

 
 
  • 1
  • 2
改为:

 
 
  • 1
[build]           
compiler=msvc 

 
 
  • 1
  • 2

3.pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

PS C:\Users\peter> pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
  Cloning https://github.com/philferriere/cocoapi.git to c:\users\peter\appdata\local\temp\pip-req-build-_5h_zx6o
Building wheels for collected packages: pycocotools
  Running setup.py bdist_wheel for pycocotools ... done
  Stored in directory: C:\Users\peter\AppData\Local\Temp\pip-ephem-wheel-cache-f2p0wo9j\wheels\69\2b\12\2fa959e49f73d26cff202c2f4e5079096c9c57c8a8509fd75c
Successfully built pycocotools
Installing collected packages: pycocotools
Successfully installed pycocotools-2.0
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  1. ok!

这里是这个文件的地址,有需要的小伙伴可以自行下载
https://gist.github.com/cgpeter96/c56d28798faec5e689cf6139e8341d39

                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-e44c3c0e64.css" rel="stylesheet">
                </div>
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值