파이썬(Python) jpype 설치시 에러

    다른 컴퓨터에서는 에러가 발생하지 않았지만, 회사에 있는 컴퓨터에서 파이썬에 konlpy(파이썬 한국어 형태소 분석기)를 호출하기 위해 필요한 jpype라는 라이브러리를 설치하는 도중에 "Microsoft Visual C++ 14.0 is required" 에러가 발생했습니다. 해결 방법이 다양하게 있는 것으로 보이나(stackoverflow나 주변에 있는 사람들이 말한 내용들을 토대로 하면..) 제 경우에는 별도의 추가 설치를 하는 것으로 해결이 됐습니다.


    문제를 쉽게 해결하려는 노력보다 이럴땐 정공법을 택해서 가는 것이 더 나아 보입니다. maven 하나로 모든 것이 끝나버리는 자바 개발자로서 파이썬의 이런 자질구레한 상황들로 개발이 지연될 때는 좀 짜증나긴 합니다. 물론 자바 개발도 세팅하면 농담으로 프로젝트 50% 끝났네라는 말을 하긴 하지만 말이죠. 




    에러 콘솔 로그


    C:\Anaconda3\python.exe "C:/Project/AI/00. SAI/02. PySource/chatbot/chatbot.py"

    Traceback (most recent call last):

      File "C:/Project/AI/00. SAI/02. PySource/chatbot/chatbot.py", line 10, in <module>

        from konlpy.tag import Twitter

      File "C:\Anaconda3\lib\site-packages\konlpy\__init__.py", line 15, in <module>

        from . import tag

      File "C:\Anaconda3\lib\site-packages\konlpy\tag\__init__.py", line 4, in <module>

        from ._hannanum import Hannanum

      File "C:\Anaconda3\lib\site-packages\konlpy\tag\_hannanum.py", line 7, in <module>

        import jpype

    ImportError: No module named 'jpype'


    Process finished with exit code 1


    위 로그는 일단 jpype가 설치가 안되어서 발생한 No module named 에러입니다. 당연히 pip3 명령어로 jpype를 설치하면 될거라 생각해서 "pip3 install jpype"를 실행해봤습니다만, 아래와 같은 추가적인 에러가 발생하였습니다.



    C:\Windows\System32>pip3 install jpype1

    Collecting jpype1

      Downloading https://files.pythonhosted.org/packages/c4/4b/60a3e63d51714d4d7ef1

    b1efdf84315d118a0a80a5b085bb52a7e2428cdc/JPype1-0.6.3.tar.gz (168kB)

        100% |################################| 174kB 465kB/s

    Building wheels for collected packages: jpype1

      Running setup.py bdist_wheel for jpype1 ... error

      Complete output from command c:\anaconda3\python.exe -u -c "import setuptools,

     tokenize;__file__='C:\\Users\\user\\AppData\\Local\\Temp\\pip-build-vn4kc1d8\\j

    pype1\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().repla

    ce('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d

     C:\Users\user\AppData\Local\Temp\tmpzedf5_k_pip-wheel- --python-tag cp35:

      Found native jni.h at C:\Program Files\Java\jdk1.8.0_111\include

      running bdist_wheel

      running build

      running build_py

      creating build

      creating build\lib.win-amd64-3.5

      creating build\lib.win-amd64-3.5\jpype

      copying jpype\imports.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\JClassUtil.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\nio.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\reflect.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_classpath.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_core.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_cygwin.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_darwin.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_gui.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jarray.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jboxed.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jclass.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jcollection.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jexception.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jio.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jobject.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jpackage.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jproxy.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jvmfinder.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_jwrapper.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_linux.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_properties.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_pykeywords.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_refdaemon.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\_windows.py -> build\lib.win-amd64-3.5\jpype

      copying jpype\__init__.py -> build\lib.win-amd64-3.5\jpype

      creating build\lib.win-amd64-3.5\jpype\awt

      copying jpype\awt\__init__.py -> build\lib.win-amd64-3.5\jpype\awt

      creating build\lib.win-amd64-3.5\jpype\awt\event

      copying jpype\awt\event\WindowAdapter.py -> build\lib.win-amd64-3.5\jpype\awt\

    event

      copying jpype\awt\event\__init__.py -> build\lib.win-amd64-3.5\jpype\awt\event


      creating build\lib.win-amd64-3.5\jpypex

      copying jpypex\__init__.py -> build\lib.win-amd64-3.5\jpypex

      creating build\lib.win-amd64-3.5\jpypex\swing

      copying jpypex\swing\AbstractAction.py -> build\lib.win-amd64-3.5\jpypex\swing


      copying jpypex\swing\pyutils.py -> build\lib.win-amd64-3.5\jpypex\swing

      copying jpypex\swing\__init__.py -> build\lib.win-amd64-3.5\jpypex\swing

      running build_ext

      C:\Users\user\AppData\Local\Temp\pip-build-vn4kc1d8\jpype1\setup.py:173: Featu

    reNotice: Turned ON Numpy support for fast Java array access

        FeatureNotice)

      building '_jpype' extension

      error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C+

    + Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools


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

      Failed building wheel for jpype1

      Running setup.py clean for jpype1

    Failed to build jpype1

    Installing collected packages: jpype1

      Running setup.py install for jpype1 ... error

        Complete output from command c:\anaconda3\python.exe -u -c "import setuptool

    s, tokenize;__file__='C:\\Users\\user\\AppData\\Local\\Temp\\pip-build-vn4kc1d8\

    \jpype1\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().rep

    lace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --re

    cord C:\Users\user\AppData\Local\Temp\pip-xm9lf38c-record\install-record.txt --s

    ingle-version-externally-managed --compile:

        Found native jni.h at C:\Program Files\Java\jdk1.8.0_111\include

        running install

        running build

        running build_py

        creating build

        creating build\lib.win-amd64-3.5

        creating build\lib.win-amd64-3.5\jpype

        copying jpype\imports.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\JClassUtil.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\nio.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\reflect.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_classpath.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_core.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_cygwin.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_darwin.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_gui.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jarray.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jboxed.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jclass.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jcollection.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jexception.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jio.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jobject.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jpackage.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jproxy.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jvmfinder.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_jwrapper.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_linux.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_properties.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_pykeywords.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_refdaemon.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\_windows.py -> build\lib.win-amd64-3.5\jpype

        copying jpype\__init__.py -> build\lib.win-amd64-3.5\jpype

        creating build\lib.win-amd64-3.5\jpype\awt

        copying jpype\awt\__init__.py -> build\lib.win-amd64-3.5\jpype\awt

        creating build\lib.win-amd64-3.5\jpype\awt\event

        copying jpype\awt\event\WindowAdapter.py -> build\lib.win-amd64-3.5\jpype\aw

    t\event

        copying jpype\awt\event\__init__.py -> build\lib.win-amd64-3.5\jpype\awt\eve

    nt

        creating build\lib.win-amd64-3.5\jpypex

        copying jpypex\__init__.py -> build\lib.win-amd64-3.5\jpypex

        creating build\lib.win-amd64-3.5\jpypex\swing

        copying jpypex\swing\AbstractAction.py -> build\lib.win-amd64-3.5\jpypex\swi

    ng

        copying jpypex\swing\pyutils.py -> build\lib.win-amd64-3.5\jpypex\swing

        copying jpypex\swing\__init__.py -> build\lib.win-amd64-3.5\jpypex\swing

        running build_ext

        C:\Users\user\AppData\Local\Temp\pip-build-vn4kc1d8\jpype1\setup.py:173: Fea

    tureNotice: Turned ON Numpy support for fast Java array access

          FeatureNotice)

        building '_jpype' extension

        error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual

    C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools


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

    Command "c:\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:

    \\Users\\user\\AppData\\Local\\Temp\\pip-build-vn4kc1d8\\jpype1\\setup.py';f=get

    attr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.clo

    se();exec(compile(code, __file__, 'exec'))" install --record C:\Users\user\AppDa

    ta\Local\Temp\pip-xm9lf38c-record\install-record.txt --single-version-externally

    -managed --compile" failed with error code 1 in C:\Users\user\AppData\Local\Temp

    \pip-build-vn4kc1d8\jpype1\



    시행착오


    에러 로그를 읽어보면, Microsoft Visual C++ 14.0 이 필요하다고 나오는데.. 저걸 설치할 필요가 있을까 싶어서, 구글링한 결과 아래와 같이 명령어를 수행하면 된다고도 나와 있어서, 시행착오를 했습니다(스택오버플로우에서 찾은 내용입니다)


    pip install --upgrade setuptools


    위와 같이 pip setuptools라는 것을 실행해봐도 역시나 에러만 발생하더군요. 주변 사람에게 물어보면 jpype 할때 아무런 문제가 안났다는 말도 있어서, 혹시나 윈도우 버전이 달라서 생긴 문제 인가 싶어서 Microsoft Visual C++ 14.0 build tool을 설치해보기로 했습니다.


    https://www.visualstudio.com/vs/older-downloads/



    위 링크를 들어간 후 스크롤을 내리면, Redistributables and Build Tools 라는 항목이 있고, 첫번째 Microsoft Build Tools 2015 Update 3라는 것이 있습니다. 저는 이것을 설치 했습니다. 2017년 버전을 굳이 설치할 필요가 있을까 싶어서 최소 요구사항인 2015년 버전을 설치했습니다.



    파일을 실행하면 위와 같이 Visual Studio Build Tools가 알아서 설치됩니다. 그냥 Next 쭉 하다가 완료하면 됩니다. 빌드툴을 모두 설치하고 다시 pip로 jpype의 설치를 시도 해봤습니다.



    결과




    C:\Project\AI\00. SAI\02. PySource\JPype1-0.6.3>pip3 install JPype1

    Collecting JPype1

      Using cached https://files.pythonhosted.org/packages/c4/4b/60a3e63d51714d4d7ef

    1b1efdf84315d118a0a80a5b085bb52a7e2428cdc/JPype1-0.6.3.tar.gz

    Building wheels for collected packages: JPype1

      Running setup.py bdist_wheel for JPype1 ... done

      Stored in directory: C:\Users\user\AppData\Local\pip\Cache\wheels\0e\2b\e8\c0b

    818ac4b3d35104d35e48cdc7afe27fc06ea277feed2831a

    Successfully built JPype1

    Installing collected packages: JPype1

    Successfully installed JPype1-0.6.3


    위와 같이 깔끔하게 Jpype가 설치가 되었습니다. no module named가 발생했던 파이썬 파일을 실행해보았습니다.



    성공적으로 파일이 실행된 내용을 볼 수 있습니다. 에러는 역시 정공법으로 진행하는게 좋은 것 같습니다.

    댓글

    Designed by JB FACTORY