操作
pip install pyahocorasick -i https://pypi.tuna.tsinghua.edu.cn/simple/
说明:ahocorasick在库中名字为pyahocorasick!对症下药,否则事倍功半。
ubuntu16.04,Python:No module named 'ahocorasick',并且用上述方法操作报以下错误。
Traceback (most recent call last):
File "build_LawGraph.py", line 4, in <module>
from app import APP_ROOT,APP_STATIC
File "/home/ubuntu/AppKG/app.py", line 48, in <module>
from chatAssistant import *
File "/home/ubuntu/AppKG/chatAssistant.py", line 1, in <module>
from question_classifier import *
File "/home/ubuntu/AppKG/question_classifier.py", line 3, in <module>
import ahocorasick
ImportError: No module named 'ahocorasick'
(py3.5) ubuntu@iZ2ze8ev92ug3n3tbc2cisZ:~/AppKG$ pip install pyahocorasick -i https://pypi.tuna.tsinghua.edu.cn/simple/
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting pyahocorasick
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/9f/f0d8e8850e12829eea2e778f1c90e3c53a9a799b7f412082a5d21cd19ae1/pyahocorasick-1.4.0.tar.gz (312 kB)
|████████████████████████████████| 312 kB 437 kB/s
Building wheels for collected packages: pyahocorasick
Building wheel for pyahocorasick (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/ubuntu/.virtualenvs/py3.5/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-deqn67jo/pyahocorasick/setup.py'"'"'; __file__='"'"'/tmp/pip-install-deqn67jo/pyahocorasick/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 /tmp/pip-wheel-zx7w1ebg
cwd: /tmp/pip-install-deqn67jo/pyahocorasick/
Complete output (11 lines):
running bdist_wheel
running build
running build_ext
building 'ahocorasick' extension
creating build
creating build/temp.linux-x86_64-3.5
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DAHOCORASICK_UNICODE= -I/home/ubuntu/.virtualenvs/py3.5/include -I/usr/include/python3.5m -c pyahocorasick.c -o build/temp.linux-x86_64-3.5/pyahocorasick.o
In file included from pyahocorasick.c:13:0:
common.h:14:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for pyahocorasick
Running setup.py clean for pyahocorasick
Failed to build pyahocorasick
Installing collected packages: pyahocorasick
Running setup.py install for pyahocorasick ... error
ERROR: Command errored out with exit status 1:
command: /home/ubuntu/.virtualenvs/py3.5/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-deqn67jo/pyahocorasick/setup.py'"'"'; __file__='"'"'/tmp/pip-install-deqn67jo/pyahocorasick/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-yfsggsuu/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/.virtualenvs/py3.5/include/site/python3.5/pyahocorasick
cwd: /tmp/pip-install-deqn67jo/pyahocorasick/
Complete output (11 lines):
running install
running build
running build_ext
building 'ahocorasick' extension
creating build
creating build/temp.linux-x86_64-3.5
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DAHOCORASICK_UNICODE= -I/home/ubuntu/.virtualenvs/py3.5/include -I/usr/include/python3.5m -c pyahocorasick.c -o build/temp.linux-x86_64-3.5/pyahocorasick.o
In file included from pyahocorasick.c:13:0:
common.h:14:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/ubuntu/.virtualenvs/py3.5/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-deqn67jo/pyahocorasick/setup.py'"'"'; __file__='"'"'/tmp/pip-install-deqn67jo/pyahocorasick/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-yfsggsuu/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/.virtualenvs/py3.5/include/site/python3.5/pyahocorasick Check the logs for full command output.
经过仔细观察发现是ubuntu16.04由于是新机子,gcc的一些依赖库没有安装好。
对于这个错误:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
安装依赖库解决:
sudo apt-get install build-essential python3-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev
OK,解决!