配置python 环境时,遇到关于 lmdb 模块的问题。
工作需要,下载 rknn-toolkit 开发套件时,需要事先进行python 环境配置,然后就遇到这个问题,卡了我好久。。。。。(还是自己菜,唉。)BUG具体如下:**
这是开始的命令,它就是BUG的潘多拉魔盒:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ pip install -r ./requirements-cpu.txt
** 中间有很长一段是第三方库安装成功的记录,就不给你们看了,直接看BUG处吧,下面其实有大半都是红色字体,复制过来我不会弄,搞成全是一样的颜色了。:**
Using cached https://files.pythonhosted.org/packages/c0/4e/fd492e91abdc2d2fcb70ef453064d980688762079397f779758e055f6575/Markdown-3.1.1-py2.py3-none-any.whl
Building wheels for collected packages: lmdb
Building wheel for lmdb (setup.py) ... error
ERROR: Complete output from command /home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-vg8t53ai/lmdb/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-u2ozrkg_ --python-tag cp36:
ERROR: py-lmdb: Using bundled liblmdb; override with LMDB_FORCE_SYSTEM=1.
py-lmdb: Using CPython extension; override with LMDB_FORCE_CFFI=1.
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/lmdb
copying lmdb/cffi.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__main__.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/tool.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/_config.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__init__.py -> build/lib.linux-x86_64-3.6/lmdb
running build_ext
building 'cpython' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lmdb
creating build/temp.linux-x86_64-3.6/lib
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ilib/py-lmdb -Ilib -I/usr/include/python3.6m -I/home/shopping1/venv/include/python3.6m -c lmdb/cpython.c -o build/temp.linux-x86_64-3.6/lmdb/cpython.o -UNDEBUG -w
lmdb/cpython.c:42:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for lmdb
Running setup.py clean for lmdb
Failed to build lmdb
Installing collected packages: lmdb, decorator, networkx, typing, typing-extensions, onnx, itsdangerous, MarkupSafe, Jinja2, click, Werkzeug, flask, dill, opencv-python, ruamel.yaml, wrapt, keras-applications, tensorflow-estimator, grpcio, gast, keras-preprocessing, absl-py, markdown, tensorboard, google-pasta, astor, termcolor, tensorflow
Running setup.py install for lmdb ... error
ERROR: Complete output from command /home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-vg8t53ai/lmdb/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-yamu_5n9/install-record.txt --single-version-externally-managed --compile --install-headers /home/shopping1/venv/include/site/python3.6/lmdb:
ERROR: py-lmdb: Using bundled liblmdb; override with LMDB_FORCE_SYSTEM=1.
py-lmdb: Using CPython extension; override with LMDB_FORCE_CFFI=1.
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/lmdb
copying lmdb/cffi.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__main__.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/tool.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/_config.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__init__.py -> build/lib.linux-x86_64-3.6/lmdb
running build_ext
building 'cpython' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lmdb
creating build/temp.linux-x86_64-3.6/lib
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ilib/py-lmdb -Ilib -I/usr/include/python3.6m -I/home/shopping1/venv/include/python3.6m -c lmdb/cpython.c -o build/temp.linux-x86_64-3.6/lmdb/cpython.o -UNDEBUG -w
lmdb/cpython.c:42:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command "/home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-vg8t53ai/lmdb/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-yamu_5n9/install-record.txt --single-version-externally-managed --compile --install-headers /home/shopping1/venv/include/site/python3.6/lmdb" failed with error code 1 in /tmp/pip-install-vg8t53ai/lmdb/
回到主题,字里行间都提到 lmdb 这个库,所以我猜想是不是它没法安装引起的,于是想到自己手动安装。一开始输入 python ,进入python 命令行里下载,结果不行:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ python
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> pip install lmdb
File "<stdin>", line 1
pip install lmdb
^
SyntaxError: invalid syntax
>>> pip install lmdb
File "<stdin>", line 1
pip install lmdb
^
SyntaxError: invalid syntax
>>> quit()
后来退出 python 命令行,在ubuntu 终端里,输入以下命令:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ pip install lmdb
Collecting lmdb
Using cached https://files.pythonhosted.org/packages/86/5c/6ad690daeaa00b328606bf2fa435244a11cc2dd9aedac6ef4d2ef2a21f6e/lmdb-0.96.tar.gz
Building wheels for collected packages: lmdb
Building wheel for lmdb (setup.py) ... error
ERROR: Complete output from command /home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-bzqbulh7/lmdb/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-dnybrxi9 --python-tag cp36:
ERROR: py-lmdb: Using bundled liblmdb; override with LMDB_FORCE_SYSTEM=1.
py-lmdb: Using CPython extension; override with LMDB_FORCE_CFFI=1.
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/lmdb
copying lmdb/cffi.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__main__.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/tool.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/_config.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__init__.py -> build/lib.linux-x86_64-3.6/lmdb
running build_ext
building 'cpython' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lmdb
creating build/temp.linux-x86_64-3.6/lib
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ilib/py-lmdb -Ilib -I/usr/include/python3.6m -I/home/shopping1/venv/include/python3.6m -c lmdb/cpython.c -o build/temp.linux-x86_64-3.6/lmdb/cpython.o -UNDEBUG -w
lmdb/cpython.c:42:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for lmdb
Running setup.py clean for lmdb
Failed to build lmdb
Installing collected packages: lmdb
Running setup.py install for lmdb ... error
ERROR: Complete output from command /home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-bzqbulh7/lmdb/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-7cmwe2vk/install-record.txt --single-version-externally-managed --compile --install-headers /home/shopping1/venv/include/site/python3.6/lmdb:
ERROR: py-lmdb: Using bundled liblmdb; override with LMDB_FORCE_SYSTEM=1.
py-lmdb: Using CPython extension; override with LMDB_FORCE_CFFI=1.
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/lmdb
copying lmdb/cffi.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__main__.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/tool.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/_config.py -> build/lib.linux-x86_64-3.6/lmdb
copying lmdb/__init__.py -> build/lib.linux-x86_64-3.6/lmdb
running build_ext
building 'cpython' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/lmdb
creating build/temp.linux-x86_64-3.6/lib
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Ilib/py-lmdb -Ilib -I/usr/include/python3.6m -I/home/shopping1/venv/include/python3.6m -c lmdb/cpython.c -o build/temp.linux-x86_64-3.6/lmdb/cpython.o -UNDEBUG -w
lmdb/cpython.c:42:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
ERROR: Command "/home/shopping1/venv/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-bzqbulh7/lmdb/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-7cmwe2vk/install-record.txt --single-version-externally-managed --compile --install-headers /home/shopping1/venv/include/site/python3.6/lmdb" failed with error code 1 in /tmp/pip-install-bzqbulh7/lmdb/
发现这个错误和上面的错误是一样的,这证明我的猜想是对的,BUG和 lmdb 有关,于是再次输入:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ sudo pip install lmdb
[sudo] password for shopping1:
The directory '/home/shopping1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/shopping1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting lmdb
Downloading https://files.pythonhosted.org/packages/86/5c/6ad690daeaa00b328606bf2fa435244a11cc2dd9aedac6ef4d2ef2a21f6e/lmdb-0.96.tar.gz (869kB)
100% |████████████████████████████████| 870kB 22kB/s
Installing collected packages: lmdb
Running setup.py install for lmdb ... done
Successfully installed lmdb-0.96
试着这样输入,结果成功安装,当时真快要叫出来,不过还好没叫,很快就打脸了。
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ pip install -r ./requirements-cpu.txt
再次输入这个鬼命令,满心欢喜的等待它全部KO的时候,又报错了,和上面一样,草。在怀疑自己刚才是不是真的成功安装了 lmdb 时,输入下面命令看了一样,启发了我:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ sudo pip install lmdb
The directory '/home/shopping1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/shopping1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: lmdb in /usr/local/lib/python2.7/dist-packages
可以看见该库安装在 python 2.7下面,而我输入以下:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ python --version
Python 3.6.8
这两个对不上,所以怀疑是不是库默认安装路径错,应该安装在python3.6下面。所以,有以下操作。
先卸载 lmdb 库:
(venv) [email protected]:/usr/local/lib/python3.6/dist-packages$ sudo pip uninstall lmdb
[sudo] password for shopping1:
The directory '/home/shopping1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling lmdb-0.96:
/usr/local/lib/python2.7/dist-packages/lmdb-0.96-py2.7.egg-info
/usr/local/lib/python2.7/dist-packages/lmdb/__init__.py
/usr/local/lib/python2.7/dist-packages/lmdb/__init__.pyc
/usr/local/lib/python2.7/dist-packages/lmdb/__main__.py
/usr/local/lib/python2.7/dist-packages/lmdb/__main__.pyc
/usr/local/lib/python2.7/dist-packages/lmdb/_config.py
/usr/local/lib/python2.7/dist-packages/lmdb/_config.pyc
/usr/local/lib/python2.7/dist-packages/lmdb/cffi.py
/usr/local/lib/python2.7/dist-packages/lmdb/cffi.pyc
/usr/local/lib/python2.7/dist-packages/lmdb/cpython.so
/usr/local/lib/python2.7/dist-packages/lmdb/tool.py
/usr/local/lib/python2.7/dist-packages/lmdb/tool.pyc
Proceed (y/n)? y
Successfully uninstalled lmdb-0.96
再重新安装,记得加好路径,而且该路径是你目前使用 python 版本的路径,这点要记得。
(venv) [email protected]:/usr/local/lib/python3.6/dist-packages$ sudo pip install --target=./ lmdb
The directory '/home/shopping1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/shopping1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting lmdb
Downloading https://files.pythonhosted.org/packages/86/5c/6ad690daeaa00b328606bf2fa435244a11cc2dd9aedac6ef4d2ef2a21f6e/lmdb-0.96.tar.gz (869kB)
100% |████████████████████████████████| 870kB 20kB/s
Installing collected packages: lmdb
Running setup.py install for lmdb ... done
Successfully installed lmdb-0.96
因为我在目标目录里,所以这样写,你们不要学我啊!!! 之后再次输入命令:
(venv) [email protected]:~/rk3399pro_linux/external/rknn-toolkit/packages$ sudo pip install -r ./requirements-cpu.txt
在揪心了几分钟后,终于好了,BUG解除!!!发个纪录,分享一下喜悦。
Successfully uninstalled tensorflow-0.9.0
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.5 absl-py-0.7.1 astor-0.8.0
backports.weakref-1.0.post1 click-7.0 decorator-4.4.0 dill-0.2.8.2 flask-1.1.1 flatbuffers-1.9 funcsigs-1.0.2
futures-3.3.0 gast-0.2.2 google-pasta-0.1.7 grpcio-1.22.0 h5py-2.9.0 itsdangerous-1.1.0
keras-applications-1.0.8 keras-preprocessing-1.1.0 lmdb-0.96 markdown-3.1.1 mock-3.0.5 networkx-1.11 onnx-1.5.0
opencv-python-4.1.0.25 protobuf-3.9.0 ruamel.ordereddict-0.4.13 ruamel.yaml-0.15.82 scipy-1.2.2 tensorboard-1.14.0
tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 typing-3.7.4 typing-extensions-3.7.4 wrapt-1.11.2
这个鬼东西卡了我好几个小时,特意发帖纪录,共同进步!!!
上一篇: Centos7安装