프로그래밍

[python] pypreprocessor 설치하기

채윤아빠 2020. 6. 16. 08:56
728x90
반응형

문제점 및 증상

"pypreprocessor" 패키지를 설치하기 위하여 "pip3 install pypreprocessor" 명령을 수행하였으나, 다음과 같은 오류가 발생하며 설치가 되지 않는 문제가 발생하였습니다.


D:\Dev\Python\Test>pip3 install pypreprocessor
Collecting pypreprocessor
  Downloading pypreprocessor-0.7.7.tar.gz (10 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\dev\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-install-cgii9j96\\pypreprocessor\\setup.py'"'"'; __file__='"'"'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-install-cgii9j96\\pypreprocessor\\setup.py'"'"';f=getattr(tokenize, 
'"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\USER\AppData\Local\Temp\pip-pip-egg-info-9qh5h_gg'
         cwd: C:\Users\USER\AppData\Local\Temp\pip-install-cgii9j96\pypreprocessor\
    Complete output (7 lines):
    Traceback (most recent call last):
      File "", line 1, in 
      File "C:\Users\USER\AppData\Local\Temp\pip-install-cgii9j96\pypreprocessor\setup.py", line 16, in 
        from tests import RunTests
      File "C:\Users\USER\AppData\Local\Temp\pip-install-cgii9j96\pypreprocessor\tests\__init__.py", line 11, in 
        from tests import maintest
    ImportError: cannot import name 'maintest' from partially initialized module 'tests' (most likely due to a circular import) (C:\Users\USER\AppData\Local\Temp\pip-install-cgii9j96\pypreprocessor\tests\__init__.py)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

원인 분석

오류 메시지의 내용으로 보면, 'maintest' 모듈이 "circular import" 되어 발생한 것으로, 최신 등록된 소스 자체의 문제입니다.

해결 방안

구글링으로 해결책을 찾았습니다.

다음과 같은 명령으로 실행하면 "pypreprocessor" 패키지를 정상적으로 설치할 수 있습니다.


D:\Dev\Python\Test>pip3 install git+https://github.com/Epikem/pypreprocessor
Collecting git+https://github.com/Epikem/pypreprocessor
  Cloning https://github.com/Epikem/pypreprocessor to c:\users\user\appdata\local\temp\pip-req-build-2boiguxs
  Running command git clone -q https://github.com/Epikem/pypreprocessor 'C:\Users\USER\AppData\Local\Temp\pip-req-build-2boiguxs'
Using legacy setup.py install for pypreprocessor, since package 'wheel' is not installed.
Installing collected packages: pypreprocessor
    Running setup.py install for pypreprocessor ... done
Successfully installed pypreprocessor-0.7.7

https://github.com/interpreters/pypreprocessor/blob/master/Examples/debug2production.py 에서 제공하는 예제 코드로 "debug", "production", "postprocessed" 별로 실제 코드가 실행되는 것을 확인할 수 있습니다.

참고로 vscode에서 매개변수를 주려면, ".vscode/launch.json" 파일을 열어서 다음과 같이 "args" 항목을 추가합니다.


    "configurations": [
        {
            "name": "Python: Current File",
            "args": ["debug"],
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]

참고 자료