> Python > Windows에서 pandas사용시 cx_Freeze로 build 후 실행시 ImportError: Missing required dependencies[‘numpy’] 해결 하는 방법

Windows에서 pandas사용시 cx_Freeze로 build 후 실행시 ImportError: Missing required dependencies[‘numpy’] 해결 하는 방법

문제 발생 환경 정보

  • Windows 8.1 K
  • Python 3.4.4 (32bit)
  • cx-Freeze 4.3.4
  • pandas 0.19.2
  • numpy 1.12.0

기존 application의 요건이 추가되어 pandas를 사용하게 되었다.
작업이 마무리 되어 cx_Freeze로 build를 수행할때까지는 별 문제가 없었지만 exe를 실행해보니 다음과 같은 error가 발생되었다.

cx_Freeze_numpy

결국은 ImportError: Missing required dependencies [‘numpy’] 가 발생한 것인데 build log를 살펴보면 정상적으로 numpy를 추출한 것 같기에 난감한 상황이 되었다.

먼저 setup.py의 buildOptions에 numpy를 명시적으로 적어 주어봤다.

buildOptions = dict(packages=[],
excludes=[‘tkinter’, ’email’, ‘html’, ‘http’, ‘unittest’, ‘urllib’, ‘ctypes’, ‘distutils’],
includes=[‘numpy’, ‘wx.xml’],
include_msvcr=True)

증상은 동일 했다.
packages에도 numpy를 넣어봤지만 역시나 동일한 증상이 발생되며 해결되지 않았다.

일단 찾아보니 cx_Freeze가 작년말(2016년 11월경) 커다란 update가 있었기도 했고 현재 5.0.1 version이 stable version이므로 cx_Freeze를 5.0.1로 재설치하여 다시 시도해 봤다.

문제 해결을 위해 재설치한 환경 정보

  • cx_Freeze 5.0.1

그런데…

ImportError: Missing required dependencies [‘_methods’]

어라? error message가 바뀌었다.
위에 적진 않았지만 error message를 자세히 보니 _methods는 numpy.core package에 있는 _methods.py 였다.
위에 includes에 추가한 numpy 처럼 동일하게 처리 해보았다.

buildOptions = dict(packages=[],
excludes=[‘tkinter’, ’email’, ‘html’, ‘http’, ‘unittest’, ‘urllib’, ‘ctypes’, ‘distutils’],
includes=[‘numpy’, ‘numpy.core._methods’, ‘wx.xml’],
include_msvcr=True)

그랬더니…

ImportError: Missing required dependencies [‘distutils’]

이젠 ImportError가 친근하게 느껴질 정도이다.
excludes에서 distutils를 제거해보니 이번엔 ctypes에서 ImportError가 발생했다.
반복하다 결국 ImportError는 다음과 같은 buildOptions에서 해결되었다.

buildOptions = dict(packages=[],
excludes=[‘tkinter’, ‘html’],
includes=[‘numpy’, ‘numpy.core._methods’, ‘wx.xml’],
include_msvcr=True)

cx_Freeze에서의 ImportError관련 부분은 글을 쓰는 현재 기준(2017.03.24) issue가 등록된 상태이다.

[관련 링크]
conda env: ImportError: Missing required dependencies [‘numpy’]
cx_Freeze 5.0.1 do not find some modules that cx_Freeze 5.0 did
Missing modules in numpy and other packages

위에서 언급하진 않았지만 cx_Freeze를 5.0.1로 변경하였더니 build시 module이 library.zip으로 압축되어 생기질 않았다.
죄다 folder로 풀려버리는 증상이 있었다.

cx_Freeze_module_out

cx_Freeze 5.x로 version up이 되면서 변경사항이 있었는데 이와 연관된 이유인것 같다.
(cx_Freeze release note의 2, 3번 항목 참조)

현재 사용할 수 있는 option중에 몇 가지 방법을 시도해 보다 결국 다음과 같은 식으로 해결을 했다.
다만 library.zip은 더이상 생성되지 않는다. 다만 module 폴더들이 사라진다.

buildOptions = dict(packages=[],
excludes=[‘tkinter’, ‘html’],
includes=[‘numpy’, ‘numpy.core._methods’, ‘wx.xml’],
zip_include_packages=[‘*’],
zip_exclude_packages=[‘numpy’, ‘numpy.core._methods’],
include_msvcr=True)

하지만 이렇게 해도 zip_exclude_packages에 정의한 module은 폴더가 남는다.
원래 module이 폴더로 풀려버리는 증상은 별도 post로 작성하려 했으나 zip_exclude_package 항목때문에 한 post에 묶을 수 밖에 없었다.

zip_exclude_packages에 numpy, numpy.core_methods를 추가하지 않으면 애초에 문제가 되었던 ImportError: Missing required dependencies [‘numpy’]가 다시 발생하게 된다.

현재 issue로 등록되어있듯이 cx_Freeze에서 module import와 관련된 부분 어딘가에 bug가 있는 것 같다.

카테고리:Python
  1. 댓글이 없습니다.
  1. No trackbacks yet.

댓글 남기기