获取“错误:命令出错,退出状态为 1:"尝试安装 mysql 时 [英] Getting "ERROR: Command errored out with exit status 1:" when trying to install mysql

查看:57
本文介绍了获取“错误:命令出错,退出状态为 1:"尝试安装 mysql 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试为 python 安装 mysql 包时出现此错误:

I get this error when I try to install mysql package for python:

C:\Windows\system32>pip install mysql
Collecting mysql
  Using cached https://files.pythonhosted.org/packages/bf/5f/b574ac9f70811df0540e403309f349a8b9fa1a25d3653824c32e52cc1f28/mysql-0.0.2.tar.gz
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
Installing collected packages: mysqlclient, mysql
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\program files (x86)\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Uros\\AppData\\Local\\Temp\\pip-install-67_bzzjm\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Uros\\AppData\\Local\\Temp\\pip-install-67_bzzjm\\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 'C:\Users\Uros\AppData\Local\Temp\pip-record-wbot1jpz\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Uros\AppData\Local\Temp\pip-install-67_bzzjm\mysqlclient\
    Complete output (24 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.8
    creating build\lib.win32-3.8\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.8\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.8\MySQLdb
    creating build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.8\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.8\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\program files (x86)\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Uros\\AppData\\Local\\Temp\\pip-install-67_bzzjm\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Uros\\AppData\\Local\\Temp\\pip-install-67_bzzjm\\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 'C:\Users\Uros\AppData\Local\Temp\pip-record-wbot1jpz\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

推荐答案

我遇到了同样的问题.我没有安装 mysql,而是安装了一个 MySQL 连接器来连接到 MySQL 数据库:

I had the same problem. Instead of installing mysql I installed a MySQL connector to connect to MySQL database:

pip install mysql-connector-python

这是 Python 脚本连接到 MySQL 的样子:

This is how the Python script looks like to connects to MySQL:

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  passwd="yourpassword"
)

这篇关于获取“错误:命令出错,退出状态为 1:"尝试安装 mysql 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆