Windows下安装pymssql 常见错误及解决方法

错误一

ERROR: Command errored out with exit status 1:
command: ‘e:\python38\python.exe’ -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-mt89hzm_\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-mt89hzm_\pymssql\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 ‘C:\Users\wang9\AppData\Local\Temp\pip-pip-egg-info-qsowisnk’
cwd: C:\Users\wang9\AppData\Local\Temp\pip-install-mt89hzm_\pymssql
Complete output (7 lines):
e:\python38\lib\site-packages\setuptools\dist.py:45: DistDeprecationWarning: Do not call this function
warnings.warn(“Do not call this function”, DistDeprecationWarning)
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\wang9\AppData\Local\Temp\pip-install-mt89hzm_\pymssql\setup.py”, line 88, in
from Cython.Distutils import build_ext as _build_ext
ModuleNotFoundError: No module named ‘Cython’
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我们可以看到分割线上面的第一行内容:
ModuleNotFoundError: No module named ‘Cython’

意思就是缺少这个模块,所以我们可以直接安装这个模块:

python -m pip install cython

再次运行就不会报这个错误了

错误二

ERROR: Command errored out with exit status 1:
command: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\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\wang9\AppData\Local\Temp\pip-record-s76hp15x\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’
cwd: C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql
Complete output (16 lines):
E:\python38\lib\site-packages\setuptools\dist.py:45: DistDeprecationWarning: Do not call this function
warnings.warn(“Do not call this function”, DistDeprecationWarning)
setup.py: platform.system() => ‘Windows’
setup.py: platform.architecture() => (‘64bit’, ‘WindowsPE’)
running install
running build
running build_ext
cythoning src_mssql.pyx to src_mssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\src_mssql.pxd
tree = Parsing.p_module(s, pxd, full_module_name)
warning: src_mssql.pyx:150:4: Exception already a builtin Cython type
cythoning src\pymssql.pyx to src\pymssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\src\pymssql.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building ‘_mssql’ 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: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-8jpscfaa\pymssql\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\wang9\AppData\Local\Temp\pip-record-s76hp15x\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’ Check the logs for full command output.

还是看分割线上面第一行:
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 这个环境
安装包下载地址:https://pan.baidu.com/s/188G-kvNRHi9cCfCxOaWyvQ
提取码:y7y1

下载完成后直接安装就可以了

错误三

ERROR: Command errored out with exit status 1:
command: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\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\wang9\AppData\Local\Temp\pip-record-y5hiy9r0\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’
cwd: C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql
Complete output (23 lines):
E:\python38\lib\site-packages\setuptools\dist.py:45: DistDeprecationWarning: Do not call this function
warnings.warn(“Do not call this function”, DistDeprecationWarning)
setup.py: platform.system() => ‘Windows’
setup.py: platform.architecture() => (‘64bit’, ‘WindowsPE’)
running install
running build
running build_ext
cythoning src_mssql.pyx to src_mssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\src_mssql.pxd
tree = Parsing.p_module(s, pxd, full_module_name)
warning: src_mssql.pyx:150:4: Exception already a builtin Cython type
cythoning src\pymssql.pyx to src\pymssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\src\pymssql.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building ‘_mssql’ extension
creating build
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\freetds\vs2015_64\include -IC:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\build\include -IE:\python38\include -IE:\python38\include “-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\8.1\include\shared” “-IC:\Program Files (x86)\Windows Kits\8.1\include\um” “-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt” /Tcsrc_mssql.c /Fobuild\temp.win-amd64-3.8\Release\src_mssql.obj -DMSDBLIB
_mssql.c
src_mssql.c(607): fatal error C1083: Cannot open include file: ‘sqlfront.h’: No such file or directory
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe’ failed with exit status 2
----------------------------------------
ERROR: Command errored out with exit status 1: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-kqototoj\pymssql\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\wang9\AppData\Local\Temp\pip-record-y5hiy9r0\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’ Check the logs for full command output.

看分割线上面第二行内容:
src_mssql.c(607): fatal error C1083: Cannot open include file: ‘sqlfront.h’: No such file or directory

意思是没有这个文件或文件夹,但其实这里不止一个文件,当你保存好这个文件后,他又会报错没有另一个文件或文件夹,所以这里我把所有文件都提供给大家,大家下载后可以把文件夹里的所有文件都复制到python安装目录中的include目录中。再次执行安装命令,应该就不会报错了。

错误四

ERROR: Command errored out with exit status 1:
command: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\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\wang9\AppData\Local\Temp\pip-record-_uoh8yju\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’
cwd: C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql
Complete output (28 lines):
E:\python38\lib\site-packages\setuptools\dist.py:45: DistDeprecationWarning: Do not call this function
warnings.warn(“Do not call this function”, DistDeprecationWarning)
setup.py: platform.system() => ‘Windows’
setup.py: platform.architecture() => (‘64bit’, ‘WindowsPE’)
running install
running build
running build_ext
cythoning src_mssql.pyx to src_mssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\src_mssql.pxd
tree = Parsing.p_module(s, pxd, full_module_name)
warning: src_mssql.pyx:150:4: Exception already a builtin Cython type
cythoning src\pymssql.pyx to src\pymssql.c
E:\python38\lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive ‘language_level’ not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\src\pymssql.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
building ‘_mssql’ extension
creating build
creating build\temp.win-amd64-3.8
creating build\temp.win-amd64-3.8\Release
creating build\temp.win-amd64-3.8\Release\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\freetds\vs2015_64\include -IC:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\build\include -IE:\python38\include -IE:\python38\include “-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\8.1\include\shared” “-IC:\Program Files (x86)\Windows Kits\8.1\include\um” “-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt” /Tcsrc_mssql.c /Fobuild\temp.win-amd64-3.8\Release\src_mssql.obj -DMSDBLIB
_mssql.c
src_mssql.c(13887): warning C4244: ‘=’: conversion from ‘Py_ssize_t’ to ‘int’, possible loss of data
src_mssql.c(19220): warning C4267: ‘=’: conversion from ‘size_t’ to ‘int’, possible loss of data
src_mssql.c(30204): warning C4146: unary minus operator applied to unsigned type, result still unsigned
creating C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\build\lib.win-amd64-3.8
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\build\lib /LIBPATH:C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\freetds\vs2015_64\lib /LIBPATH:E:\python38\libs /LIBPATH:E:\python38\PCbuild\amd64 “/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64” iconv.lib replacements.lib db-lib.lib tds.lib tdsutils.lib ws2_32.lib wsock32.lib kernel32.lib shell32.lib /EXPORT:PyInit__mssql build\temp.win-amd64-3.8\Release\src_mssql.obj /OUT:build\lib.win-amd64-3.8_mssql.cp38-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.8\Release\src_mssql.cp38-win_amd64.lib
LINK : fatal error LNK1181: cannot open input file ‘iconv.lib’
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe’ failed with exit status 1181
----------------------------------------
ERROR: Command errored out with exit status 1: ‘E:\python38\python.exe’ -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\setup.py’"’"’; file=’"’"‘C:\Users\wang9\AppData\Local\Temp\pip-install-7nfiir_3\pymssql\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\wang9\AppData\Local\Temp\pip-record-_uoh8yju\install-record.txt’ --single-version-externally-managed --compile --install-headers ‘E:\python38\Include\pymssql’ Check the logs for full command output.

看分割线上面第二行:
LINK : fatal error LNK1181: cannot open input file ‘iconv.lib’

意思是缺少这个库,大家可以去下载这个文件,然后放到目录 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib 中。
这个方法我没有亲身试验过,所以有试过的朋友可以在评论中留言,说明一下这个方法管不管用,或者出现了什么问题。

如果最后还是安不上,那在这里我提供一种最直接的安装方法

到这个网址中:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql
下载对应python版本对应Windows版本的whl文件
Windows下安装pymssql 常见错误及解决方法_第1张图片
然后将下载的whl文件放入python的安装目录中,比如我的python安装目录是 E:\python38 那么我就应该将whl文件放入该目录中,此时我下载的文件所处的目录是 E:\python38\pymssql-2.1.4-cp38-cp38-win_amd64.whl

然后 win+r 输入 cmd 进入命令字符界面,将目录切换到你的python安装目录,然后执行 pip install 命令

E:\python38>pip install pymssql-2.1.4-cp38-cp38-win_amd64.whl

我们可以看到提示:

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing e:\python38\pymssql-2.1.4-cp38-cp38-win_amd64.whl
Installing collected packages: pymssql
Successfully installed pymssql-2.1.4

最后一句,成功安装pymssql。

做一个小小的科普:
上面的显示结果中有一个WARNING警告,WARNING警告提示我们pip正被一个旧的脚本包装器调用,这种命令格式在以后可能会被弃用,所以会存在一些问题,所以他推荐我们安装使用 python -m pip install 安装模块 这种格式的安装命令,所以以后安装模块可以用这种格式的安装命令

这是我目前为止安装pymssql所遇到的错误和一般的解决方法,如果在排查错误中出现什么问题或者有什么其他的错误,可以在评论区留言,这样我们可以一起讨论一起解决。

你可能感兴趣的:(Python,python)