Python开发篇——添加mysqlclient

最近使用mysql8.0,于是我就尝试用Django的框架。但是执行poetry add mysqlclient却出现了错误:

(python3.7) dison@dison-X450LD:~/workstation/project/script_scheduler$ poetry add mysqlclient
Using version ^2.0.3 for mysqlclient

Updating dependencies
Resolving dependencies... (0.1s)

Package operations: 1 install, 0 updates, 0 removals

? Installing mysqlclient (2.0.3): Failed

EnvCommandError

Command [‘/home/dison/miniconda3/envs/python3.7/bin/pip‘, ‘install‘, ‘--no-deps‘, ‘file:///home/dison/.cache/pypoetry/artifacts/62/65/91/bcefed4d522a6f6269f2052d15faa4291b24d11c2b8722ef54c370b813/mysqlclient-2.0.3.tar.gz‘] errored with the following return code 1, and output: 
Processing /home/dison/.cache/pypoetry/artifacts/62/65/91/bcefed4d522a6f6269f2052d15faa4291b24d11c2b8722ef54c370b813/mysqlclient-2.0.3.tar.gz
    ERROR: Command errored out with exit status 1:
    command: /home/dison/miniconda3/envs/python3.7/bin/python -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"‘"‘/tmp/pip-req-build-8vtznvan/setup.py‘"‘"‘; __file__=‘"‘"‘/tmp/pip-req-build-8vtznvan/setup.py‘"‘"‘;f=getattr(tokenize, ‘"‘"‘open‘"‘"‘, open)(__file__);code=f.read().replace(‘"‘"‘\r\n‘"‘"‘, ‘"‘"‘\n‘"‘"‘);f.close();exec(compile(code, __file__, ‘"‘"‘exec‘"‘"‘))‘ egg_info --egg-base /tmp/pip-pip-egg-info-fbnd90o_
        cwd: /tmp/pip-req-build-8vtznvan/
    Complete output (15 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    mysql_config --version
    mariadb_config --version
    mysql_config --libs
    Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-req-build-8vtznvan/setup.py", line 15, in <module>
        metadata, options = get_config()
        File "/tmp/pip-req-build-8vtznvan/setup_posix.py", line 70, in get_config
        libs = mysql_config("libs")
        File "/tmp/pip-req-build-8vtznvan/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    ----------------------------------------
WARNING: Discarding file:///home/dison/.cache/pypoetry/artifacts/62/65/91/bcefed4d522a6f6269f2052d15faa4291b24d11c2b8722ef54c370b813/mysqlclient-2.0.3.tar.gz. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.


at ~/.poetry/lib/poetry/utils/env.py:1101 in _run
    1097│                 output = subprocess.check_output(
    1098│                     cmd, stderr=subprocess.STDOUT, **kwargs
    1099│                 )
    1100│         except CalledProcessError as e:
    → 1101│             raise EnvCommandError(e, input=input_)
    1102│ 
    1103│         return decode(output)
    1104│ 
    1105│     def execute(self, bin, *args, **kwargs):

仔细检查是我通过docker部署mysql并没有提供mysql的开发环境。这里我就执行了sudo apt-get install libmysqlclient-dev(我电脑返厂维修了,只能先用ubuntu20.04的旧笔电凑合一下)
安装好后就可以正常添加mysqlclient

(python3.7) dison@dison-X450LD:~/workstation/project/script_scheduler$ poetry add mysqlclient
Using version ^2.0.3 for mysqlclient

Updating dependencies
Resolving dependencies... (0.2s)

Package operations: 1 install, 0 updates, 0 removals

参考:

Python开发篇——添加mysqlclient

上一篇:Android仿易信界面SlidingMenu左右滑动


下一篇:Android应用性能优化