pip安装jsonlib失败:安装VS编译工具后仍遇LNK1120错误
安装jsonlib时遇到的编译链接错误求助
执行pip install jsonlib时首次报错,提示需安装Microsoft Visual C++ 14.0及以上版本。安装Visual Studio Build Tools 2022的C++组件并重启终端后,再次执行安装命令,出现LNK2001和LNK1120链接错误,搜索exit code 1120未找到有效解决方法,两次错误完整日志如下:
ERROR 1
C:\Users\sheld>pip install jsonlib Collecting jsonlib Downloading jsonlib-1.6.1.tar.gz (43 kB) ---------------------------------------- 43.8/43.8 kB 2.2 MB/s eta 0:00:00 Preparing metadata (setup.py) ... done Installing collected packages: jsonlib DEPRECATION: jsonlib is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for jsonlib ... error error: subprocess-exited-with-error × Running setup.py install for jsonlib did not run successfully. │ exit code: 1 ╰─> [11 lines of output] running install C:\Users\sheld\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build\lib.win-amd64-cpython-311 copying jsonlib.py -> build\lib.win-amd64-cpython-311 running build_ext building '_jsonlib' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output]
ERROR 2
C:\Users\sheld>pip install jsonlib Collecting jsonlib Using cached jsonlib-1.6.1.tar.gz (43 kB) Preparing metadata (setup.py) ... done Installing collected packages: jsonlib DEPRECATION: jsonlib is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for jsonlib ... error error: subprocess-exited-with-error × Running setup.py install for jsonlib did not run successfully. │ exit code: 1 ╰─> [59 lines of output] running install C:\Users\sheld\AppData\Local\Programs\Python\Python311\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_py creating build creating build\lib.win-amd64-cpython-311 copying jsonlib.py -> build\lib.win-amd64-cpython-311 running build_ext building '_jsonlib' extension creating build\temp.win-amd64-cpython-311 creating build\temp.win-amd64-cpython-311\Release "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\sheld\AppData\Local\Programs\Python\Python311\include -IC:\Users\sheld\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt" /Tc_jsonlib.c /Fobuild\temp.win-amd64-cpython-311\Release\_jsonlib.obj _jsonlib.c _jsonlib.c(98): warning C4996: 'PyUnicode_AsUnicode': deprecated in 3.3 _jsonlib.c(99): warning C4996: 'PyUnicode_GetSize': deprecated in 3.3 _jsonlib.c(310): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(348): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(396): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(450): warning C4013: 'PyLong_FromUnicode' undefined; assuming extern returning int _jsonlib.c(450): warning C4047: '=': 'PyObject *' differs in levels of indirection from 'int' _jsonlib.c(550): warning C4018: '<': signed/unsigned mismatch _jsonlib.c(643): warning C4020: 'PyFloat_FromString': too many actual parameters _jsonlib.c(656): warning C4047: '=': 'PyObject *' differs in levels of indirection from 'int' _jsonlib.c(638): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(1186): warning C4013: 'PyString_CheckExact' undefined; assuming extern returning int _jsonlib.c(1188): warning C4013: 'PyString_Check' undefined; assuming extern returning int _jsonlib.c(1208): warning C4013: 'PyObject_Unicode' undefined; assuming extern returning int _jsonlib.c(1208): warning C4047: '=': 'PyObject *' differs in levels of indirection from 'int' _jsonlib.c(1406): warning C4013: 'PyInt_CheckExact' undefined; assuming extern returning int _jsonlib.c(1466): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1467): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3 _jsonlib.c(1517): warning C4013: 'PyString_AS_STRING' undefined; assuming extern returning int _jsonlib.c(1517): warning C4047: 'function': 'const char *' differs in levels of indirection from 'int' _jsonlib.c(1517): warning C4024: 'ascii_constant': different types for formal and actual parameter 1 _jsonlib.c(1539): warning C4013: 'PyInt_Check' undefined; assuming extern returning int _jsonlib.c(1702): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1703): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3 _jsonlib.c(1751): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(1755): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1782): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1783): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3 _jsonlib.c(1821): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(1825): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1931): warning C4047: '=': 'const char *' differs in levels of indirection from 'int' _jsonlib.c(1970): warning C4047: 'function': 'const char *' differs in levels of indirection from 'int' _jsonlib.c(1970): warning C4024: 'serializer_append_ascii': different types for formal and actual parameter 2 _jsonlib.c(1993): warning C4996: 'PyUnicode_AS_UNICODE': deprecated in 3.3 _jsonlib.c(1994): warning C4996: 'PyUnicode_GET_SIZE': deprecated in 3.3 _jsonlib.c(2089): warning C4013: 'PyUnicode_Encode' undefined; assuming extern returning int _jsonlib.c(2090): warning C4047: '=': 'PyObject *' differs in levels of indirection from 'int' _jsonlib.c(2095): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(2124): warning C4047: '=': 'PyObject *' differs in levels of indirection from 'int' _jsonlib.c(2129): warning C4996: 'PyUnicode_FromUnicode': deprecated in 3.3 _jsonlib.c(2161): warning C4013: 'Py_InitModule3' undefined; assuming extern returning int "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\sheld\AppData\Local\Programs\Python\Python311\libs /LIBPATH:C:\Users\sheld\AppData\Local\Programs\Python\Python311 /LIBPATH:C:\Users\sheld\AppData\Local\Programs\Python\Python311\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x64" /EXPORT:PyInit__jsonlib build\temp.win-amd64-cpython-311\Release\_jsonlib.obj /OUT:build\lib.win-amd64-cpython-311\_jsonlib.cp311-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-311\Release\_jsonlib.cp311-win_amd64.lib LINK : error LNK2001: unresolved external symbol PyInit__jsonlib build\temp.win-amd64-cpython-311\Release\_jsonlib.cp311-win_amd64.lib : fatal error LNK1120: 1 unresolved externals error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure × Encountered error while trying to install package. ╰─> jsonlib note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure.
解决建议
- 优先替换为现代JSON库:jsonlib的1.6.1版本最后更新是2009年,完全不兼容Python3.11这类高版本。Python3.2及以上自带的
json模块已经足够满足绝大多数JSON处理需求,无需额外安装。如果需要更高性能,可直接安装ujson或orjson,执行pip install ujson即可,这些包提供预编译的wheel,无需本地编译。 - 若必须使用jsonlib:
- 降级Python到2.7或3.2以下版本(不推荐,这些版本已停止安全维护)
- 手动修改源码适配Python3.11:需要替换所有废弃的Python C API(如将
PyUnicode_AsUnicode改为PyUnicode_AsUTF8,替换Py_InitModule3为Python3的模块初始化方式,添加PyInit__jsonlib函数),但修改成本极高,后续可能还会出现更多兼容性问题。
内容的提问来源于stack exchange,提问作者sw016428
相关产品推荐
相关产品推荐

