2020-01-28
pip로 mysqlclient설치시 아래와 같은 오류가 뜨곤 한다.
C:\>pip install mysqlclient==1.4.6 Collecting mysqlclient==1.4.6 Using cached https://files.pythonhosted.org/packages/f8/9b/5db9a03e2088a87c26e3e4d4c7f7e8f4c2dbae610f9521cdfac15755a795/mysqlclient-1.4.6.tar.gz Building wheels for collected packages: mysqlclient Building wheel for mysqlclient (setup.py) ... error ERROR: Command errored out with exit status 1: command: 'C:\ProgramData\Anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\pip-install-12yzf7u5\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\pip-install-12yzf7u5\\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 'C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-wheel-4ey87nvs' --python-tag cp37 cwd: C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-install-12yzf7u5\mysqlclient\ Complete output (24 lines): running bdist_wheel running build running build_py creating build creating build\lib.win32-3.7 creating build\lib.win32-3.7\MySQLdb copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb creating build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\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/ ----------------------------------------
가장 확실한 해결방법은, 위 에러에서 Microsoft Visual C++ 14.0가 필요하다고 되어 있듯이, Visual Studio를 설치하면 해결된다.
하지만 Visual Studio를 설치하는 것은 많은 시간과 용량이 필요하다. 이럴때는 아래 링크로 가서 자신의 환경에 맞는 파일을 받아서 설치하면 된다.

링크: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

필자가 설치하려던 mysqlclient버전은 1.4.6이었고, python의 버전은 3.7이었다. 그리고, 해당 python은 32bit였기에 mysqlclient-1.4.6-cp37-cp37m-win32.whl 파일을 받아서 설치했다.
C:\>pip install C:\Users\Administrator\Downloads\mysqlclient-1.4.6-cp37-cp37m-win32.whl Processing c:\users\administrator\downloads\mysqlclient-1.4.6-cp37-cp37m-win32.whl Installing collected packages: mysqlclient Successfully installed mysqlclient-1.4.6
참고로 pip로 설치시에 윈도우에서는 글로벌로 설치가 잘 안될 수도 있기 때문에, 해당 폴더에 가서 설치를 해야 제대로 적용 될 것이다.