Help us understand the problem. What is going on with this article?

Sublime Text で pythonbrew

More than 5 years have passed since last update.

==========================

Sublime TextのPluginのPythonのバージョンは2.6.7なのでバージョンを3.2や2.7などから切替えて使いたいです。

Macでversion_info.pyをcommand+bでBuildすると2.7.1のバージョンが表示されます。

version_info.py
import sys
print sys.version_info
sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)

pythonbrewのpathがSublime Textに通っていないのでバージョンの切替が反映されませんので、少しpythonbrewに手をいれて対応させます。

pythonbrewのバージョンの切替でシンボリックリンクを作成

pybrewのswitchとuseでバージョンを切替えたときにカレントバージョンのシンボリックリンクを作ります。
run_commandの最後に追加します。(switchとuseは同じコードです。)

~/.pythonbrew/scripts/pythonbrew/commands/switch.py
def run_command(self, options, args):

  # (略)

  path = os.path.abspath(os.path.join(PATH_PYTHONS, '..', 'current'))
  if os.path.isdir(path):
      os.unlink(path)
  os.symlink(os.path.abspath(os.path.join(PATH_PYTHONS, pkgname)), path)
~/.pythonbrew/scripts/pythonbrew/commands/use.py
def run_command(self, options, args):

  # (略)

  path = os.path.abspath(os.path.join(PATH_PYTHONS, '..', 'current'))
  if os.path.isdir(path):
      os.unlink(path)
  os.symlink(os.path.abspath(os.path.join(PATH_PYTHONS, pkgname)), path)

Sublime Textにpathを設定

PackagesのPythonのPython.sublime-buildにpathを追加します。
(userは任意に変更して下さい。)

Python.sublime-build
{
  "cmd": ["python", "-u", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python",
  "path": "/Users/user/.pythonbrew/current/bin:/usr/bin:/bin:/usr/sbin:/sbin"
}

pythonbrewでバージョンを切替えてバージョンを確認

まずはuseで確認

$ pybrew use 2.7.2

command+bでバージョンを確認すると2.7.2が表示されます。

sys.version_info(major=2, minor=7, micro=2, releaselevel='final', serial=0)

つぎにswitchで確認

$ pybrew switch 2.6.7

command+bでバージョンを確認すると2.6.7が表示されます。

(2, 6, 7, 'final', 0)

バージョンの切替がSublime Textに反映されるようになりました。

ogomr
RubyKansai, naniwa.rb, DDD.rb, CoderDojo Osakasayama/Hommachi, OSS Gate Osaka, Rails Girls Osaka, Open Source Software Developers Osaka, テクノ図工部
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした