Microsoft MVP성태의 닷넷 이야기
오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가 [링크 복사], [링크+제목 복사]
조회: 3487
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

파이썬 - pymssql을 윈도우 환경에서 설치 불가

이 글은 해법을 제시하지 않고, 단지 해결을 위한 중간 단계까지의 시행착오만 담고 있습니다.




아쉽게도 pymssql은 윈도우 환경에서 (제가 방법을 모르는 걸 수도 있지만) 설치가 안 됩니다. 일단 시도를 해보면,

c:\temp> python --version
Python 3.7.3

c:\temp> python -m pip install pymssql
Collecting pymssql
  Downloading pymssql-2.2.8.tar.gz (171 kB)
     |████████████████████████████████| 171 kB 6.4 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pymssql
  Building wheel for pymssql (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Python37\python.exe' 'C:\Python37\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel '%USERPROFILE%\AppData\Local\Temp\tmpw6373io1'
       cwd: %USERPROFILE%\AppData\Local\Temp\pip-install-k5o2dacd\pymssql_49532f5aeab24dd8aff035d1baba3af9
  Complete output (41 lines):
  setup.py: platform.system() => Windows
  setup.py: platform.architecture() => ('64bit', 'WindowsPE')
  setup.py: include_dirs => []
  setup.py: library_dirs => []
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-cpython-37
  creating build\lib.win32-cpython-37\pymssql
  copying src\pymssql\__init__.py -> build\lib.win32-cpython-37\pymssql
  running build_ext
  Compiling src\pymssql\_mssql.pyx because it changed.
  [1/1] Cythonizing src\pymssql\_mssql.pyx
  building 'pymssql._mssql' extension
  creating build\temp.win32-cpython-37
  creating build\temp.win32-cpython-37\Release
  creating build\temp.win32-cpython-37\Release\src
  creating build\temp.win32-cpython-37\Release\src\pymssql
  "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\bin\HostX86\x86\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Python37\include -IC:\Python37\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\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" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\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" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc\pymssql\_mssql.c /Fobuild\temp.win32-cpython-37\Release\src\pymssql\_mssql.obj -DMSDBLIB
  _mssql.c
  src\pymssql\_mssql.c(1139): fatal error C1083: Cannot open include file: 'sqlfront.h': No such file or directory
  warning: src\pymssql\_mssql.pyx:27:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:28:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:29:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:30:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:31:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:32:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:35:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:36:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:38:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:82:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:230:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:264:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:333:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:831:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:919:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1005:12: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1379:16: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1713:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.35.32215\\bin\\HostX86\\x86\\cl.exe' failed with exit code 2
  ----------------------------------------
  ERROR: Failed building wheel for pymssql
Failed to build pymssql
ERROR: Could not build wheels for pymssql, which is required to install pyproject.toml-based projects
WARNING: You are using pip version 21.3.1; however, version 23.2.1 is available.
You should consider upgrading via the 'C:\Python37\python.exe -m pip install --upgrade pip' command.

복잡한 오류 메시지 속에 이번에도 "fatal error C1083: Cannot open include file: 'sqlfront.h': No such file or directory" 문제가 나옵니다. 따라서 아래의 글에 따라,

failed to build: Cannot open include file: 'sqlfront.h': No such file or directory
; https://github.com/pymssql/pymssql/issues/372

(리눅스에서 freetds-dev를 설치한 것처럼) x86의 경우, freetds-v0.95.95-win-x86-vs2015.zip을, x64의 경우 freetds-v0.95.95-win-x86_64-vs2015.zip을 다운로드해 압축을 풀어 INCLUDE, LIB 환경 변수를 연결해 줍니다. 아래는 요즘 세상에 x86을 쓰진 않을 테니 x64를 기준으로 환경 구성을 가정합니다.

// Visual Studio 2022의 "x64 Native Tools Command Prompt" 창을 열고,
// 여기서는 C:\temp\tds 디렉터리에 압축을 푼 것으로 가정.

set INCLUDE=C:\temp\tds\include;%INCLUDE%
set LIB=C:\temp\tds\lib-nossl;C:\temp\tds\lib-nossl\static;%LIB%

이후 컴파일 오류는 없지만 대신 link.exe 단계에서 오류가 발생합니다.

c:\temp> python -m pip install pymssql
Collecting pymssql
  Using cached pymssql-2.2.8.tar.gz (171 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: pymssql
  Building wheel for pymssql (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Python37\python.exe' 'C:\Python37\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel '%USERPROFILE%\AppData\Local\Temp\tmp0ykb3vrw'
       cwd: %USERPROFILE%\AppData\Local\Temp\pip-install-5zn5kp88\pymssql_4ecd3707a9b24eaba3f06dbae1163ed0
  Complete output (44 lines):
  setup.py: platform.system() => Windows
  setup.py: platform.architecture() => ('64bit', 'WindowsPE')
  setup.py: include_dirs => []
  setup.py: library_dirs => []
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-cpython-37
  creating build\lib.win32-cpython-37\pymssql
  copying src\pymssql\__init__.py -> build\lib.win32-cpython-37\pymssql
  running build_ext
  Compiling src\pymssql\_mssql.pyx because it changed.
  [1/1] Cythonizing src\pymssql\_mssql.pyx
  building 'pymssql._mssql' extension
  creating build\temp.win32-cpython-37
  creating build\temp.win32-cpython-37\Release
  creating build\temp.win32-cpython-37\Release\src
  creating build\temp.win32-cpython-37\Release\src\pymssql
  "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\bin\HostX86\x86\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Python37\include -IC:\Python37\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\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" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" -IC:\temp\tds\include "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Enterprise\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" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc\pymssql\_mssql.c /Fobuild\temp.win32-cpython-37\Release\src\pymssql\_mssql.obj -DMSDBLIB
  _mssql.c
  src\pymssql\_mssql.c(37094): warning C4146: unary minus operator applied to unsigned type, result still unsigned
  src\pymssql\_mssql.c(38018): warning C4146: unary minus operator applied to unsigned type, result still unsigned
  "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\bin\HostX86\x86\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:c:/Program Files/OpenSSL-Win64/lib" /LIBPATH:C:\Python37\libs /LIBPATH:C:\Python37 /LIBPATH:C:\Python37\PCbuild\win32 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x86" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x86" /LIBPATH:C:\temp\tds\lib-nossl /LIBPATH:C:\temp\tds\lib-nossl\static "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x86" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x86" replacements.lib db-lib.lib tds.lib tdsutils.lib ws2_32.lib wsock32.lib kernel32.lib shell32.lib libssl_static.lib libcrypto_static.lib crypt32.lib advapi32.lib gdi32.lib user32.lib /EXPORT:PyInit__mssql build\temp.win32-cpython-37\Release\src\pymssql\_mssql.obj /OUT:build\lib.win32-cpython-37\pymssql\_mssql.cp37-win_amd64.pyd /IMPLIB:build\temp.win32-cpython-37\Release\src\pymssql\_mssql.cp37-win_amd64.lib
  LINK : fatal error LNK1181: cannot open input file 'tdsutils.lib'
  warning: src\pymssql\_mssql.pyx:27:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:28:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:29:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:30:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:31:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:32:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:35:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:36:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:38:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:82:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:230:0: The 'DEF' statement is deprecated and will be removed in a future Cython version. Consider using global variables, constants, and in-place literals instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:264:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:333:4: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:831:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:919:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1005:12: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1379:16: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  warning: src\pymssql\_mssql.pyx:1713:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
  error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX86\\x86\\link.exe' failed with exit code 1181
  ----------------------------------------
  ERROR: Failed building wheel for pymssql
Failed to build pymssql
ERROR: Could not build wheels for pymssql which use PEP 517 and cannot be installed directly

중간에 보면 "LINK : fatal error LNK1181: cannot open input file 'tdsutils.lib'" 오류가 있는데 실제로 "C:\temp\tds" 하위 디렉터리에는 해당 파일이 없습니다.

이에 관해 이슈를 보면,

Error building pymssql on Windows - tdsutils.lib does not exist.
; https://groups.google.com/g/pymssql/c/EVbXwuM0gZk

"Mikhail Terekhov"의 답변에 해당 lib 파일은 직접 빌드해서 얻는 것처럼 나옵니다.




그런데, 이 과정이 좀 복잡합니다. 우선, build.py 파일을 다운로드하고, 실행하면,

c:\temp\tdsutil> python build.py --ws-dir=freetds --dist-dir=dist --sdist --freetds-version="1.3.4"
downloading http://ftp.freetds.org/pub/freetds/stable/freetds-1.3.4.tar.gz to c:\temp\tdsutil\freetds\freetds-1.3.4.tar.gz
downloading DONE
extracting win-iconv.zip -> c:\temp\tdsutil\freetds\win-iconv
running cmake in c:\temp\tdsutil\freetds\win-iconv
The system cannot find the path specified.
Build failed: Command '"C:\Program Files\CMake\bin\cmake.exe" -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC=on -DBUILD_SHARED=off -DBUILD_EXECUTABLE=off -DBUILD_TEST=off .' returned non-zero exit status 1.

CMake 환경을 먼저 구성해야 합니다. ^^; 제 경우에는 Visual Studio 2022의 구성 요소로 "C++ CMake tools for Windows"를 설치해 두었기 때문에 이미 "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake" 경로에 있으므로 juction 연결을 한 다음,

mklink /J "C:\Program Files\CMake" "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake"

다시 실행합니다.

c:\temp\tdsutil> python build.py --ws-dir=freetds --dist-dir=dist --sdist --freetds-version="1.3.4"
c:\temp\tdsutil\freetds\freetds-1.3.4.tar.gz already exists
c:\temp\tdsutil\freetds\win-iconv.zip already exists
downloading DONE
extracting win-iconv.zip -> c:\temp\tdsutil\freetds\win-iconv
running cmake in c:\temp\tdsutil\freetds\win-iconv
CMake Warning (dev) at CMakeLists.txt:1 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- The C compiler identification is MSVC 19.36.32535.0
-- The CXX compiler identification is MSVC 19.36.32535.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
...[생략]...
-- Installing: C:/temp/tdsutil/freetds/freetds-1.3.4-bin/lib/tdsutils.lib
-- Installing: C:/temp/tdsutil/freetds/freetds-1.3.4-bin/lib/replacements.lib
-- Installing: C:/temp/tdsutil/freetds/freetds-1.3.4-bin/lib/tds.lib
...[생략]...
-- Installing: C:/temp/tdsutil/freetds/freetds-1.3.4-bin/lib/tdssrv.lib
-- Installing: C:/temp/tdsutil/freetds/freetds-1.3.4-bin/bin/tdspool.exe
ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found.
Build failed: Command 'C:\Python37\python.exe -m pip wheel . -w c:\temp\tdsutil\dist' returned non-zero exit status 1.

비록 실패는 했지만, tdsutils.lib 파일은 빌드가 되었으므로 그 파일을 "C:\temp\tds\lib-nossl" 디렉터리에 복사 후 다시 실행하면 다른 라이브러리를 찾기 시작합니다.

replacements.lib db-lib.lib tds.lib tdsutils.lib ws2_32.lib wsock32.lib kernel32.lib shell32.lib libssl_static.lib libcrypto_static.lib crypt32.lib advapi32.lib gdi32.lib user32.lib


이것들 중에서 없는 것은 libssl_static.lib, libcrypto_static.lib 2개 파일인데, 다행히 vcpkg로 openssl을 빌드하면 구할 수 있습니다.

그래서 ^^; 다시 빌드해 볼까요?

c:\temp> python -m pip install pymssql
...[생략]...
      src\pymssql\_mssql.c(38018): warning C4146: unary minus operator applied to unsigned type, result still unsigned
      "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:c:/Program Files/OpenSSL-Win64/lib" /LIBPATH:C:\Python37\libs /LIBPATH:C:\Python37 /LIBPATH:C:\Python37\PCbuild\amd64 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\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" /LIBPATH:C:\temp\tds\lib-nossl /LIBPATH:C:\temp\tds\lib-nossl\static "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\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" replacements.lib db-lib.lib tds.lib tdsutils.lib ws2_32.lib wsock32.lib kernel32.lib shell32.lib libssl_static.lib libcrypto_static.lib crypt32.lib advapi32.lib gdi32.lib user32.lib /EXPORT:PyInit__mssql build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.obj /OUT:build\lib.win-amd64-cpython-37\pymssql\_mssql.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.cp37-win_amd64.lib
         Creating library build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.cp37-win_amd64.lib and object build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.cp37-win_amd64.exp
      tds.lib(iconv.c.obj) : error LNK2001: unresolved external symbol iconv_open
      tds.lib(iconv.c.obj) : error LNK2001: unresolved external symbol iconv_close
      tds.lib(iconv.c.obj) : error LNK2001: unresolved external symbol iconv
      build\lib.win-amd64-cpython-37\pymssql\_mssql.cp37-win_amd64.pyd : fatal error LNK1120: 3 unresolved externals

이번에는 iconv 관련 함수를 못 찾고 있습니다. 이게 약간 문제인데요, 애당초 link.exe 실행 명령을 보면 iconv.lib를 전달하지 않으므로 해당 함수들을 링킹하지 못하고 있는 것입니다. 일단 임시 방편으로 pip install 설치 시 temporary 디렉터리를 삭제하지 않도록 빌드한 다음,

c:\temp> python -m pip install pymssql --no-clean

바로 그 임시 디렉터리를 찾아,

C:\> dir /a/s lib.win-amd64-cpython-37
 Volume in drive C has no label.
 Volume Serial Number is 7090-BBAB

 Directory of %USERPROFILE%\AppData\Local\Temp\pip-install-n3akcnxs\pymssql_e28c63ffe19a49c6ade659e651329395\build

2023-08-10  오전 10:47    <DIR>          lib.win-amd64-cpython-37
               0 File(s)              0 bytes

     Total Files Listed:
               0 File(s)              0 bytes
               1 Dir(s)  317,131,005,952 bytes free

build 디렉터리를 하위로 두는 곳으로 이동해,

cd %USERPROFILE%\AppData\Local\Temp\pip-install-n3akcnxs\pymssql_e28c63ffe19a49c6ade659e651329395

iconv.lib를 담은 명령어를 우리가 직접 실행하는 것도 가능합니다.

"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:c:/Program Files/OpenSSL-Win64/lib" /LIBPATH:C:\Python37\libs /LIBPATH:C:\Python37 /LIBPATH:C:\Python37\PCbuild\amd64 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\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" /LIBPATH:C:\temp\tds\lib-nossl /LIBPATH:C:\temp\tds\lib-nossl\static "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\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" db-lib.lib tds.lib tdsutils.lib ws2_32.lib wsock32.lib kernel32.lib shell32.lib libssl_static.lib iconv.lib libcrypto_static.lib crypt32.lib advapi32.lib gdi32.lib user32.lib /EXPORT:PyInit__mssql build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.obj /OUT:build\lib.win-amd64-cpython-37\pymssql\_mssql.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-37\Release\src\pymssql\_mssql.cp37-win_amd64.lib


하지만, 그래도 오류가 발생하는데요, ^^;

...[생략]...
Generating code
Finished generating code
replacements.lib(win_mutex.c.obj) : error LNK2005: tds_win_mutex_lock already defined in tdsutils.lib(win_mutex.c.obj)
build\lib.win-amd64-cpython-37\pymssql\_mssql.cp37-win_amd64.pyd : fatal error LNK1169: one or more multiply defined symbols found

이전에 build.py로 빌드했던 tdsutils.lib와 freetds-v0.95.95-win-x86_64-vs2015.zip에 있던 replacements.lib에 동일한 tds_win_mutex_lock 함수가 중복 포함돼 있어 오류가 발생합니다. ^^;

휴... 끝이 없습니다. ^^;




다시 처음으로 돌아가서, "freetds-v0.95.95-win-x86_64-vs2015.zip" 버전 v0.95.95가 2016년 4월 2일 릴리스니까, 아마도 그때 버전의 pymssql은 잘 설치가 되었을 것입니다.

당시 버전을 보면 2.1.2인데요, 이걸로 설치해 보면 오류 메시지가 그래도 나옵니다.

c:\temp> python -m pip install pymssql==2.1.2
    ...[생략]...
      _mssql.c
      _mssql.c(10930): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
      _mssql.c(15967): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
      _mssql.c(24724): warning C4146: unary minus operator applied to unsigned type, result still unsigned
      _mssql.c(25522): error C2039: 'exc_type': is not a member of '_ts'
      C:\Python37\include\pystate.h(212): note: see declaration of '_ts'
      _mssql.c(25523): error C2039: 'exc_value': is not a member of '_ts'
      C:\Python37\include\pystate.h(212): note: see declaration of '_ts'
    ...[생략]...

빌드 과정 중 Python 설치 디렉터리의 include\pystate.h 헤더 파일을 참고하는데, 제가 실습한 Python 3.7에는 _ts 헤더 파일에 exc_type 필드가 실제로 존재하지 않았습니다.

typedef struct _ts {
    /* See Python/ceval.c for comments explaining most fields */

    struct _ts *prev;
    struct _ts *next;
    PyInterpreterState *interp;

    struct _frame *frame;
    ...[생략]...
}

그렇다면 당시 파이썬에는 있었다는 이야기인데요, 단적으로 python 2.7의 헤더를 보면,

typedef struct _ts {
    /* See Python/ceval.c for comments explaining most fields */

    struct _ts *next;
    PyInterpreterState *interp;

    struct _frame *frame;
    int recursion_depth;
    /* 'tracing' keeps track of the execution depth when tracing/profiling.
       This is to prevent the actual trace/profile code from being recorded in
       the trace/profile. */
    int tracing;
    int use_tracing;

    Py_tracefunc c_profilefunc;
    Py_tracefunc c_tracefunc;
    PyObject *c_profileobj;
    PyObject *c_traceobj;

    PyObject *curexc_type;
    PyObject *curexc_value;
    PyObject *curexc_traceback;

    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;

   ...[생략]...
}

이렇게 exc_type 필드가 보입니다. 음... 결국 적절한 파이썬 버전까지 맞춰서 빌드하면 된다는 이야기인데, 나중에 시간나면 해봐야겠습니다. 일단 현재는 여기까지만! ^^;




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/10/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13432정성태10/31/20232456오류 유형: 878. 탐색기의 WSL 디렉터리 접근 시 "Attempt to access invalid address." 오류 발생
13431정성태10/31/20232790스크립트: 60. 파이썬 - 비동기 FastAPI 앱을 gunicorn으로 호스팅
13430정성태10/30/20232679닷넷: 2153. C# - 사용자가 빌드한 ICU dll 파일을 사용하는 방법
13429정성태10/27/20232962닷넷: 2152. Win32 Interop - C/C++ DLL로부터 이중 포인터 버퍼를 C#으로 받는 예제파일 다운로드1
13428정성태10/25/20233036닷넷: 2151. C# 12 - ref readonly 매개변수
13427정성태10/18/20233250닷넷: 2150. C# 12 - 정적 문맥에서 인스턴스 멤버에 대한 nameof 접근 허용(Allow nameof to always access instance members from static context)
13426정성태10/13/20233408스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/20233196닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/20233173스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233320닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233396닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235585스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233220스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233925닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233454닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233259오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233756닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233515디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233710닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236993닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233494Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20235033닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233888닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233844Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233589닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233558VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...