博弈論開發工具Gambit的Python包安裝

博弈論在經濟、管理、計算機等各領域都有廣泛的應用,最近需要博弈論的模擬與驗證,主要開發工具是Python,就琢磨用Gambit。Gambit提供了多種接口,如果用命令行就夠的話就不用費心用Python接口了,主要是用Python比較麻煩,用官方提供的往往一下子不成功,多方實踐下來,有如下經驗:

  1. 用Python2.7版本,原因是Gambit最後更新比較早,編譯不支持Python3.X
  2. 在Linux下安裝多個編譯準備的包。

具體有篇英文帖子講了,我就不再翻譯了,複製於下:

I just managed to make the Gambit library to work in my command line.

There are many steps and mistakes you may encounter in the installation:

As @theycallhimtom said, the issue is that you need to build Gambit before you can build the python interface. Follow the instructions in the link to build Gambit first.

While building, you may encounter the error that after you clone Gambit to your local environment from Github, and go into the directory, you can't run ./configure.

You'll have to install the 3 tools/dependency they require to install: autoconf, automake, and libtool. All these can be installed using brew install ... (brew install autoconf, brew install automake, and brew install libtool)

After the installation you should try to run aclocal. If it doesn't work, you need to create an m4 directory using mkdir m4 in the Gambit directory you cloned (make sure m4 is installed, if not install it either using brew install m4 or cloning it from Github)

When you installed the m4 directory, try to run libtoolize. If it works, fine. In case it doesn't, simply add 'g' to libtoolize to make it glibtoolize and it will work (programming sometimes is like magic)

After that, automake and autoconf should work fine, if properly installed.

Try running ./configure and sudo make install to build Gambit into your system. You should have no problem here.

Get into the Python dir using cd src/python, and then try running python setup.py build.

At this point, you'll probably get an error saying gcc couldn't compile, or something like that. Don't panic. Simply open the file where the error is found (should be a c++ file), and manually correct these errors. Should be around 20 errors. All you need to do is add space to right-angled brackets (at least that's what I did)

Run sudo python setup.py install, and you should be finally able to install Gambit library into Python.
Don't follow their documentation on this page. It's outdated and doesn't work. Use their Github page instead.

That's how I could get Gambit library working for me in Python, hope it works for you!

安裝成功測試圖
英文原貼:https://stackoverflow.com/questions/30286551/cant-build-gambit-game-theory-extension

以資記錄,祝大家好運。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章