2016-10-13 18 views
5

Mac OS X El CapitanでSublim Text 3を使用しています。私がする必要があるのは、サブライムテキスト3内のPythonファイルを評価することです。SublimREPLプラグインでファイルを評価するためのPythonバージョンを変更する

SublimREPLのプラグインがインストールされています。

画面の2番目の部分にPythonインタプリタを表示するために2行のレイアウト(View > Layout > Rows: 2)を設定しました。

次に、Tools > Command Palette... > SublimeREPL: PythonでPythonインタプリタを起動します。

enter image description here

インタプリタが正しく起動し、私はこれを取得:

enter image description here

私は(これ/usr/local/bin/に設置)を手動でダウンロードしたのPython 3.5で開始する方法を見つけることができません。私はこのファイルを変更しようとしました:/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/Config/Python/Main.sublime-menuthis post命令に続いていますが、これは何も変更されませんでした(Python 2.7.10はまだ起動しました)。ここで

は私Main.sublime-menuの内容です:

[ 
    { 
     "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": ["python", "-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": ["python", "-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": ["python", "-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": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"], 
          "linux": ["python", "-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" 
         } 
        } 
        } 
       ]} 
      ] 
     }] 
    } 
] 

それでもthis postアドバイス以下、私は以下のコードの一部を変更したが、私は、フォルダ/usr/local/bin/内の任意のexeファイルを見つけることができません。

{"command": "repl_open", 
"caption": "Python - PDB current file", 
"id": "repl_python_pdb", 
"mnemonic": "D", 
"args": { 
    "type": "subprocess", 
    "encoding": "utf8", 
    "cmd": ["/usr/local/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"], 
    "cwd": "$file_path", 
    "syntax": "Packages/Python/Python.tmLanguage", 
    "external_id": "python", 
    "extend_env": {"PYTHONIOENCODING": "utf-8"} 
    } 
} 

Ctrl + , + fdocによる)を押すと、インタプリタはまだPython 2.7.10から始まります。

+0

OSXではなくLinuxでPython3.xのインストールには、 'python3'や' python35'のような名前の実行可能ファイルがあります。 '/ usr/local/bin /'が空であれば '/ usr/bin'にインストールされていて、'/Library/Frameworks/'や' – David

+0

コマンドラインで、python3を実行することができれば、 'whereis python'や' which python'がどこにあるのかを知ることができます。同様に、Python 3インタプリタの 'import site; print(site.USER_SITE) ''はpython3のsite-packagesディレクトリの場所を表示するはずです。 – David

答えて

3

誤った設定ファイルを変更しているようで、おそらくいくつか問題が発生しているようです。

私はその後Tools > Command Palette... > SublimeREPL: Python

何のコマンドパレット項目 "SublimeREPL:Pythonは" ありませんでPythonインタプリタを起動するので、私はあなたがTools > SublimeREPL > Python > Pythonを意味すると仮定しています。それは次のようなタブ何かで開きます:これまでのところは良い

Python - execnet 
Python 
Python - virtualen 
Python - PDB current file 
Python - RUN current file 
Python - IPython 

Tools > SublimeREPL > Python実際に

# *REPL* [python] 
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

は、次のようなメニューなものが表示されます。しかし、どのようにPythonのバージョンを変更するには?

理想的には、グローバルなpythonを使用するように設定する(可能ではない)か、上記のメニューにバージョンのバリエーションを追加することができます。

最も単純な回避策は、カスタムバージョンのバリアントを追加することです。

Packages/User/Menu.sublime-menuという名前のファイルを作成します(存在しない場合)。 Menu > Preferences > Browse Packages...からユーザーパッケージディレクトリを探します。そのファイルにメニューを作成します。このメニューは、が追加され、既存のメニューにが追加されます。例えば

Packages/User/Menu.sublime-menu

[ 
    { 
     "id": "tools", 
     "children": 
     [{ 
      "caption": "SublimeREPL Variants", 
      "id": "SublimeREPLVariants", 
      "children": 
      [ 
       { 
        "command": "repl_open", 
        "caption": "Python - PDB current file", 
        "id": "repl_python_pdb", 
        "mnemonic": "D", 
        "args": { 
         "type": "subprocess", 
         "encoding": "utf8", 
         "cmd": ["/usr/bin/python3", "-i", "-u", "-m", "pdb", "$file_basename"], 
         "cwd": "$file_path", 
         "syntax": "Packages/Python/Python.tmLanguage", 
         "external_id": "python", 
         "extend_env": {"PYTHONIOENCODING": "utf-8"} 
        } 
       } 
      ] 
     }] 
    } 
] 

することが重要である:それ以外の場合は、他のメニューに置き換えられますキャプションとIDは、他のメニューと同じではありません

  1. したがって、私は上記の名前を "SublimeREPL Variants"と命名しました。

  2. "cmd"は、有効なバイナリへの絶対パスを使用します。あなたはwhichのようなコマンドで正しいパスを使用しているチェックすることができます。

    のPythonの場所を検索し、それを介して:

    $ which python 
    /usr/bin/python 
    
    $ which python3 
    /usr/bin/python3 
    
    $ which python2 
    /usr/bin/python2 
    

    は追加の詳細についてもPossible to switch between python 2 and 3 in Sublime Text 3 build systems? (Windows)参照してください。

+0

実際には、ツール>コマンドパレット...> SublimeREPL:Python'メニュー:自分の投稿を表示編集してスクリーンショットを追加しました。 – wiltomap

+0

私はあなたのソリューションを試してみましたが、とにかく完璧に仕事をしました。どうもありがとう! – wiltomap

関連する問題