LoginSignup
1
0

More than 5 years have passed since last update.

PyCallで複数のPythonを使い分けて利用する

Posted at

はじめに

RubyからPyCallを使ってPythonのライブラリを利用しようとして少しはまったので、対処をまとめます。

Python2系と3系が混在

この時、必要なライブラリが同じようにインストールされていれば問題ないのですが、どちらかにしか入っていないものを利用する場合、初期で使用されるPythonのバージョンが違っているとエラーになります。

環境変数の設定

以下のとおりENV["PYTHON"]を設定することで、使用するPythonのバージョンを指定できます。

Python2の場合

#!/usr/bin/env ruby

# 環境変数の設定
ENV['PYTHON'] = "/usr/bin/python"

# PyCallの読込
require 'pycall'

Python3の場合

#!/usr/bin/env ruby

# 環境変数の設定
ENV['PYTHON'] = "/usr/bin/python3"

# PyCallの読込
require 'pycall'

できた!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0