我是Python和Python-Flask的新手,并且遇到了错误。 我正在使用Ubuntu 18.04.3 LTS和Python 2.7.15+构建一个python-flask Web应用程序。

安装flask-mysqldb时遇到错误。

$ pip install flask-mysqldb 

完整的输出:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Processing ./.cache/pip/wheels/fd/c9/ef/e0e99dfcf898bc040267e36c4a414ff0b22239968a25161012/Flask_MySQLdb-0.2.0-cp27-none-any.whl Collecting mysqlclient   Using cached https://files.pythonhosted.org/packages/f8/9b/5db9a03e2088a87c26e3e4d4c7f7e8f4c2dbae610f9521cdfac15755a795/mysqlclient-1.4.5.tar.gz Requirement already satisfied: Flask>=0.10 in ./.local/lib/python2.7/site-packages (from flask-mysqldb) (1.1.1) Requirement already satisfied: click>=5.1 in ./.local/lib/python2.7/site-packages (from Flask>=0.10->flask-mysqldb) (7.0) Requirement already satisfied: Werkzeug>=0.15 in ./.local/lib/python2.7/site-packages (from Flask>=0.10->flask-mysqldb) (0.16.0) Requirement already satisfied: itsdangerous>=0.24 in ./.local/lib/python2.7/site-packages (from Flask>=0.10->flask-mysqldb) (1.1.0) Requirement already satisfied: Jinja2>=2.10.1 in ./.local/lib/python2.7/site-packages (from Flask>=0.10->flask-mysqldb) (2.10.3) Requirement already satisfied: MarkupSafe>=0.23 in ./.local/lib/python2.7/site-packages (from Jinja2>=2.10.1->Flask>=0.10->flask-mysqldb) (1.1.1) Building wheels for collected packages: mysqlclient   Building wheel for mysqlclient (setup.py) ... error   ERROR: Command errored out with exit status 1:    command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Gno8ny/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Gno8ny/mysqlclient/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-OrgtfM --python-tag cp27        cwd: /tmp/pip-install-Gno8ny/mysqlclient/   Complete output (40 lines):   running bdist_wheel   running build   running build_py   creating build   creating build/lib.linux-x86_64-2.7   creating build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb   copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb   creating build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants   running build_ext   building 'MySQLdb._mysql' extension   creating build/temp.linux-x86_64-2.7   creating build/temp.linux-x86_64-2.7/MySQLdb   x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,4,5,'final',0) -D__version__=1.4.5 -I/usr/include/mysql -I/usr/include/python2.7 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o   MySQLdb/_mysql.c: In function ‘_mysql_field_to_python’:   MySQLdb/_mysql.c:1142:33: warning: passing argument 1 of ‘PyInt_FromString’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]            return PyInt_FromString(rowitem, NULL, 10);                                    ^~~~~~~   In file included from /usr/include/python2.7/Python.h:89:0,                    from MySQLdb/_mysql.c:38:   /usr/include/python2.7/intobject.h:37:24: note: expected ‘char *’ but argument is of type ‘const char *’    PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);                           ^~~~~~~~~~~~~~~~   x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/MySQLdb/_mysql.so   /usr/bin/ld: cannot find -lssl   /usr/bin/ld: cannot find -lcrypto   collect2: error: ld returned 1 exit status   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1   ----------------------------------------   ERROR: Failed building wheel for mysqlclient   Running setup.py clean for mysqlclient Failed to build mysqlclient Installing collected packages: mysqlclient, flask-mysqldb     Running setup.py install for mysqlclient ... error     ERROR: Command errored out with exit status 1:      command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Gno8ny/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Gno8ny/mysqlclient/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-uh9IqO/install-record.txt --single-version-externally-managed --compile          cwd: /tmp/pip-install-Gno8ny/mysqlclient/     Complete output (40 lines):     running install     running build     running build_py     creating build     creating build/lib.linux-x86_64-2.7     creating build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/compat.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb     copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb     creating build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants     running build_ext     building 'MySQLdb._mysql' extension     creating build/temp.linux-x86_64-2.7     creating build/temp.linux-x86_64-2.7/MySQLdb     x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,4,5,'final',0) -D__version__=1.4.5 -I/usr/include/mysql -I/usr/include/python2.7 -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o     MySQLdb/_mysql.c: In function ‘_mysql_field_to_python’:     MySQLdb/_mysql.c:1142:33: warning: passing argument 1 of ‘PyInt_FromString’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]              return PyInt_FromString(rowitem, NULL, 10);                                      ^~~~~~~     In file included from /usr/include/python2.7/Python.h:89:0,                      from MySQLdb/_mysql.c:38:     /usr/include/python2.7/intobject.h:37:24: note: expected ‘char *’ but argument is of type ‘const char *’      PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);                             ^~~~~~~~~~~~~~~~     x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-PPrPZj/python2.7-2.7.15=. -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/MySQLdb/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -latomic -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/MySQLdb/_mysql.so     /usr/bin/ld: cannot find -lssl     /usr/bin/ld: cannot find -lcrypto     collect2: error: ld returned 1 exit status     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1     ---------------------------------------- ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Gno8ny/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Gno8ny/mysqlclient/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-uh9IqO/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.` 

我还阅读了其他一些问题和解决方案( https://stackoverflow.com/a/51228348/12403455 ),建议使用以下方法:

mysqlclient‑1.4.5‑cp27‑cp27m‑win_amd64.whl

所以我通过使用以下命令安装了它:

 $ pip install mysqlclient-1.4.5-cp27m-win_amd64.whl 

并遇到一个错误:

Requirement 'mysqlclient‑1.4.5‑cp27‑cp27m‑win_amd64.whl' looks like a filename, but the file does not exist mysqlclient‑1.4.5‑cp27‑cp27m‑win_amd64.whl is not a valid wheel filename. 

我不确定如何解决此问题或如何进行。 任何帮助,将不胜感激。

===============>>#1 票数:0

您不能像在其他答案中找到的那样使用mysqlclient‑1.4.5‑cp27‑cp27m‑win_amd64.whl ,因为这是Windows的转盘,并且您在Linux上。

项目mysqlclientflask-mysqldb的依赖flask-mysqldb ,它不会为Linux分发wheel,因此您必须直接从源代码( mysqlclient-1.4.5.tar.gz )进行构建。

您的安装可能由于缺少构建依赖项而失败。

项目登录页面所述 ,请首先安装构建依赖项:

sudo apt-get install python-dev default-libmysqlclient-dev libssl-dev 

然后再尝试pip install --user flask-mysqldb

  ask by Rose translate from so

本文未有回复,本站智能推荐: