今天在mac上安装ctcdecode的时候碰到了很多问题,这里分享一下我的安装过程:
git clone --recursive https://github.com/parlance/ctcdecode.git
cd ctcdecode
pip install wget
pip install .
可能会报错:
(base) ➜ ctcdecode git:(master) pip install .
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Processing /Users/admin/Documents/pythonFiles/speech_recognition/ctcdecode
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 1016, in _send_output
self.send(msg)
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 956, in send
self.connect()
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 1384, in connect
super().connect()
File "/Users/admin/anaconda3/lib/python3.7/http/client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/Users/admin/anaconda3/lib/python3.7/socket.py", line 727, in create_connection
raise err
File "/Users/admin/anaconda3/lib/python3.7/socket.py", line 716, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-req-build-8prjlgea/setup.py", line 43, in
import build
File "/private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-req-build-8prjlgea/build.py", line 27, in
'third_party/openfst-1.6.7.tar.gz')
File "/private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-req-build-8prjlgea/build.py", line 16, in download_extract
wget.download(url, out=dl_path)
File "/Users/admin/anaconda3/lib/python3.7/site-packages/wget.py", line 526, in download
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 247, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Users/admin/anaconda3/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
urllib.error.URLError:
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-req-build-8prjlgea/
这需要单独下载:
# Download/Extract openfst, boost
download_extract('https://sites.google.com/site/openfst/home/openfst-down/openfst-1.6.7.tar.gz',
'third_party/openfst-1.6.7.tar.gz')
download_extract('https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.gz',
'third_party/boost_1_67_0.tar.gz')
需要自行下载这两个文件,并把它们解压到third_party
目录下,然后注释掉这两行。安装的时候你可能会遇见下面的问题:
(base) ➜ ctcdecode git:(master) ✗ pip install .
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Processing /Users/admin/Documents/pythonFiles/speech_recognition/ctcdecode
Building wheels for collected packages: ctcdecode
Building wheel for ctcdecode (setup.py) ... error
ERROR: Complete output from command /Users/admin/anaconda3/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-req-build-5guc0sqe/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 /private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-wheel-h2y7svan --python-tag cp37:
ERROR: /Users/admin/anaconda3/lib/python3.7/distutils/extension.py:131: UserWarning: Unknown Extension options: 'package', 'with_cuda'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.7-x86_64-3.7
creating build/lib.macosx-10.7-x86_64-3.7/ctcdecode
copying ctcdecode/__init__.py -> build/lib.macosx-10.7-x86_64-3.7/ctcdecode
running build_ext
/Users/admin/anaconda3/lib/python3.7/site-packages/torch/utils/cpp_extension.py:191: UserWarning:
!! WARNING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (g++) is not compatible with the compiler Pytorch was
built with for this platform, which is clang++ on darwin. Please
use clang++ to to compile your extension. Alternatively, you may
compile PyTorch from source using g++, and then you can also use
g++ to compile your extension.
See https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for help
with compiling PyTorch from source.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! WARNING !!
platform=sys.platform))
building 'ctcdecode._ext.ctc_decode' extension
creating build/temp.macosx-10.7-x86_64-3.7
creating build/temp.macosx-10.7-x86_64-3.7/ctcdecode
....
输入下面的命令:
CFLAGS=-stdlib=libc++ pip install .
安装成功:
(base) ➜ ctcdecode git:(master) ✗ CFLAGS=-stdlib=libc++ pip install .
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Processing /Users/admin/Documents/pythonFiles/speech_recognition/ctcdecode
Building wheels for collected packages: ctcdecode
Building wheel for ctcdecode (setup.py) ... done
Stored in directory: /private/var/folders/5h/mjbc_z1n7m91q21xw9_m217m0000gn/T/pip-ephem-wheel-cache-ijax0yt1/wheels/12/b1/84/2050969d4c4b54255b7ff02447919e11bcd313f8e54ed47283
Successfully built ctcdecode
Installing collected packages: ctcdecode
Successfully installed ctcdecode-0.4
[1]. macos: pip install failed. https://github.com/parlance/ctcdecode/issues/101