ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • pyinstaller를 이용한 tensorflow-gpu exe 파일 만들기
    프로그래밍/python 2018. 11. 9. 14:03
    728x90

    pyinstaller를 이용한 tensorflow-gpu exe 파일 만들기


    어찌하다 보니 Tensorflow와 Keras를 이용한 감성분석 프로그램을 만들게 되었다.(회사의 요구사항)


    감성분석을 어디다 찰떡 같이 써먹을지 예상은 안돼지만...


    고객이 해달라니 뭐...


    어찌 어찌 구글 신과 다른 분들의 도음으로 모델을 만들고 프로그램을 구현 했는데


    고객님께서 exe 파일로 만들어 달라고 하신다.


    결국은 pyinstaller를 이용해서 exe를 만들었다.


    pip install pyinstaller


    pyinstaller file.py


    일반적으로 EXE 파일이 만들어진다.


    하지만 tensorflow-gpu 를 만들고 exe를 실행하면 error 가 발생



    rs.py", line 627, in exec_module

        exec(bytecode, module.__dict__)

      File "site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importe

    rs.py", line 627, in exec_module

        exec(bytecode, module.__dict__)

      File "site-packages\tensorflow\__init__.py", line 22, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importe

    rs.py", line 627, in exec_module

        exec(bytecode, module.__dict__)

      File "site-packages\tensorflow\python\__init__.py", line 49, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importe

    rs.py", line 627, in exec_module

        exec(bytecode, module.__dict__)

      File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>

    ImportError: Traceback (most recent call last):

      File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importe

    rs.py", line 627, in exec_module

        exec(bytecode, module.__dict__)

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper

      File "importlib\__init__.py", line 126, in import_module

    ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'


    이런 에러가 발생한다. 모듈을 찾지 못한다.


    이런 때는


    dist/[project_name]/_pywrap_tensorflow_internal.pyd 



    dist/[project_name]/tensorflow/python/_pywrap_tensorflow_internal.pyd


    옮겨 주면 된다.


    일단 1차적인 문제 해결... 그 다음은...?


    ---------------------------------------------------------


    일단 위의 에러이 후 딱히 발생하는 에러는 없이 회사 내 테스트 서버에서는 잘 돌아 갔다.


    이제 고객사에 컴퓨터에 설치를 해주면 된다.


    NVIDA cuad, cudnn을 설치 하고 설정 파일들을 바꿔서 


    EXE를 실행


    하지만...


    D:\InsightEye\mw\core\sentimental_main>sentimental_main.exe

    Using TensorFlow backend.

    Traceback (most recent call last):

      File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper

      File "importlib\__init__.py", line 126, in import_module

    ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다.


    During handling of the above exception, another exception occurred:


    Traceback (most recent call last):

      File "KERAS\sentimental_main.py", line 3, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "KERAS\ui\frameui.py", line 8, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "KERAS\worker\main_worker.py", line 21, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\keras\__init__.py", line 3, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\keras\utils\__init__.py", line 6, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\keras\utils\conv_utils.py", line 9, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\keras\backend\__init__.py", line 89, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\tensorflow\__init__.py", line 22, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\tensorflow\python\__init__.py", line 49, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>

    ImportError: Traceback (most recent call last):

      File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>

      File "c:\users\aiapuser02\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in <module>

      File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper

      File "importlib\__init__.py", line 126, in import_module

    ImportError: DLL load failed: 지정된 모듈을 찾을 수 없습니다.


    란 Error 가 발생


    열심히 구글 신에게 물어 본 결과


    여러가지 말들이 많았다.


    의존성을 없애기 위해 EXE로 만들었는데 그래도 컴퓨터 내에 꼭 있어야 하는 프로그램이 있었다.(WINDOW OS 기준)


    Microsoft Visual C++ 2015 Redistributable


    가 설치 되어 있어야 했다.

    결국 해당 프로그램을 설치하고

    프로그램은 잘 동작




    728x90
Designed by Tistory.