Kudos
Collect
Twiiter
Facebook
Share
개발의 'ㄱ'자라도 아는 날을 기대하며...

맥용 서브라임 패키지 sublimeREPL 에서 파이썬3가 실행안되는 문제 해결방법

마지막 업데이트 3년 전
0 0 0 0
이 글은 시리즈 ‘맥용 서브라임텍스트에서 파이썬3 실행하기’ 의 4 번째 포스팅입니다. 시리즈 더보기

서브라임에서 대학교 파이썬3 과제를 하다가, sublimeREPL 에서 제대로 실행되지 않아 해결방법을 찾게 되어 적어놓습니다.

sublimeREPL의 ‘Python - RUN current file’ 메뉴 실행 에러

sublimeREPL 의 Python - RUN current file를 선택하면 지금 코딩하고 있는 파이썬 프로그램을 실행해볼 수 있는데, sublimeREPL 을 설치하고 바로 실행하게 되면 맥에 기본으로 설치되어 있는 파이썬 2.7.10 버전으로 실행되어, 파이썬3로 코딩한 것은 SyntaxError 등의 에러가 나게 됩니다.

예) sublimeREPL 파이썬3 코드 실행 에러
예) sublimeREPL 파이썬3 코드 실행 에러

이를 해결하기 위해 다음의 설정이 필요합니다.

sublimeREPL 에서 파이썬3 설정하기

  1. 서브라임에서 sublimeREPL 의 설정파일을 엽니다. 설정파일 Main.sublime-menu는 다음의 경로에 있습니다.
/Users/{유저계정}/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu

참고로 Library 등의 폴더는 숨겨진 폴더라서 파인더에서 보이질 않습니다. 숨겨진 폴더를 표시하려면 단축키 Cmd + shift + . 을 누르면 표시됩니다. 단축키를 다시 누르면 숨겨집니다.

  1. 설정파일 안에 있는 내용 중에 “cmd”에 있는 “python”python3로 수정합니다.
“cmd”의 “python”을 “python3”로 변경한다.
“cmd”의 “python”을 “python3”로 변경한다.

참고를 위해 Main.sublime-menu의 python3 로 수정된 코드를 적어놓습니다.

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "R",
            "id": "SublimeREPL",
            "children":
            [
                {"caption": "Python",
                "id": "Python",

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python",
                     "id": "repl_python",
                     "mnemonic": "P",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python3", "-i", "-u"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "python_virtualenv_repl",
                     "id": "python_virtualenv_repl",
                     "caption": "Python - virtualenv"},
                    {"command": "repl_open",
                     "caption": "Python - PDB current file",
                     "id": "repl_python_pdb",
                     "mnemonic": "D",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python3", "-i", "-u", "-m", "pdb", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "R",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python3", "-u", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - IPython",
                     "id": "repl_python_ipython",
                     "mnemonic": "I",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": {
                            "osx": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "linux": ["python3", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
                        },
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }
                    }
                ]}
            ]
        }]
    }
]
  1. 수정한 파일을 저장하면 sublimeREPL에서 파이썬3로 빌드되어 실행됩니다.

참조

안녕하세요?^^ 개발자라는 소리를 듣고 싶어 늦은 나이에 개발의 세계에 몸담게 된 Brad 라고 합니다. 아직 개발의 'ㄱ' 자도 모르지만, 개발을 배우면서 알게되는 것들을 림프에 정리해보려고 합니다. 저의 부족한 글이 누군가에게 조금이나마 도움이 되길 바랍니다.

연재
맥용 sublimetext 에서 파이썬3를 실행하는 방법입니다. 파이썬3 설치부터 패키지 설치까지 작성해보았습니다.
Essedrop - 이미지 주소를 만드는 가장 빠른 방법
 

독자 의견

저자 @brad 에게 의견 남기기:

Please sign in to comment.
Markdown is also available in comment.