gambitproject / gambit

Gambit: The package for computation in game theory
http://www.gambit-project.org
GNU General Public License v2.0
406 stars 151 forks source link

Support for Python3? #203

Closed pamdla closed 5 years ago

pamdla commented 7 years ago

I downloaded gambit-15.1 from github, and installed to my python site-packages folder. However, it seems that I can ONLY install gambit with Python2.7, but Python3.5/Python3.6 will throw error that saying "dict is not writable".

robert-7 commented 7 years ago

I'm not 100% I can help with this, but could you please give the full error message you're getting when trying to install?

tturocy commented 7 years ago

This is correct - Python 3 is not supported at present (but we would always welcome patches to add such support!)

pamdla commented 7 years ago

@tturocy Thank you for your confirmation. @robert-7 I tried to produce the exact error message I had encountered with Python3 in my virtual env, however I could not make it install while came to your comment&request.

Tehnrry commented 7 years ago

How to install the gambit to the python site-packages folder.When I use python setup.py install, encountering some errors. (Python2.7 on win10)

E:\gambit-15.1.0\src\python>python setup.py install running install running bdist_egg running egg_info writing gambit.egg-info\PKG-INFO writing top-level names to gambit.egg-info\top_level.txt writing dependency_links to gambit.egg-info\dependency_links.txt writing entry points to gambit.egg-info\entry_points.txt reading manifest file 'gambit.egg-info\SOURCES.txt' writing manifest file 'gambit.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py running build_ext skipping 'gambit/lib\libgambit.cpp' Cython extension (up-to-date) building 'gambit.lib.libgambit' extension C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I../.. -I.. "-IC:\Program Files (x86)\Python\Python27\include" "-IC:\Program Files (x86)\Python\Python27\PC" /Tpgambit/lib\libgambit.cpp /Fobuild\temp.win-amd64-2.7\Release\gambit/lib\libgambit.obj libgambit.cpp C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc e:\gambit-15.1.0\src\libgambit\game.h(841) : warning C4290: C++ exception specification ignored except to indicate a function is not declspec(nothrow) e:\gambit-15.1.0\src\libagg\proj_func.h(104) : warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data e:\gambit-15.1.0\src\libagg\trie_map.h(134) : error C3646: 'attribute' : unknown override specifier e:\gambit-15.1.0\src\libagg\trie_map.h(577) : see reference to class template instantiation 'trie_map' being compiled e:\gambit-15.1.0\src\libagg\trie_map.h(134) : error C2061: syntax error : identifier 'always_inline' e:\gambit-15.1.0\src\libagg\trie_map.h(134) : error C2091: function returns function e:\gambit-15.1.0\src\libagg\trie_map.h(456) : error C2061: syntax error : identifier 'noinline' e:\gambit-15.1.0\src\libagg\trie_map.h(456) : error C2144: syntax error : 'void' should be preceded by ';' e:\gambit-15.1.0\src\libagg\trie_map.h(456) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int e:\gambit-15.1.0\src\libagg\trie_map.h(456) : warning C4183: 'attribute__': missing return type; assumed to be a member function returning 'int' e:\gambit-15.1.0\src\libagg\trie_map.h(487) : error C2061: syntax error : identifier 'noinline' e:\gambit-15.1.0\src\libagg\trie_map.h(487) : error C2144: syntax error : 'void' should be preceded by ';' e:\gambit-15.1.0\src\libagg\trie_map.h(487) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int e:\gambit-15.1.0\src\libagg\trie_map.h(487) : error C2238: unexpected token(s) preceding ';' e:\gambit-15.1.0\src\libagg\trie_map.h(487) : error C2143: syntax error : missing ';' before '' e:\gambit-15.1.0\src\libagg\trie_map.h(519) : error C2238: unexpected token(s) preceding ';' e:\gambit-15.1.0\src\libagg\trie_map.imp(28) : error C2065: 'x' : undeclared identifier e:\gambit-15.1.0\src\libagg\trie_map.imp(49) : error C2433: 'trie_map::insert' : 'inline' not permitted on data declarations e:\gambit-15.1.0\src\libagg\trie_map.imp(49) : warning C4346: 'trie_map::value_type' : dependent name is not a type prefix with 'typename' to indicate a type e:\gambit-15.1.0\src\libagg\trie_map.imp(49) : error C2350: 'trie_map::insert' is not a static member e:\gambit-15.1.0\src\libagg\trie_map.imp(53) : error C2065: 'always_inline' : undeclared identifier e:\gambit-15.1.0\src\libagg\trie_map.imp(53) : error C2448: 'attribute' : function-style initializer appears to be a function definition e:\gambit-15.1.0\src\libagg\trie_map.imp(54) : error C2065: 'V' : undeclared identifier e:\gambit-15.1.0\src\libagg\trie_map.imp(54) : error C2065: 'V' : undeclared identifier e:\gambit-15.1.0\src\libagg\trie_map.imp(61) : error C2509: 'find' : member function not declared in 'trie_map' e:\gambit-15.1.0\src\libagg\trie_map.h(70) : see declaration of 'trie_map' e:\gambit-15.1.0\src\libagg\trie_map.imp(66) : error C2065: 'k' : undeclared identifier e:\gambit-15.1.0\src\libagg\trie_map.imp(74) : error C2433: 'trie_map::findExact' : 'inline' not permitted on data declarations e:\gambit-15.1.0\src\libagg\trie_map.imp(74) : warning C4346: 'trie_map::key_type' : dependent name is not a type prefix with 'typename' to indicate a type e:\gambit-15.1.0\src\libagg\trie_map.imp(74) : error C2470: 'trie_map::findExact' : looks like a function definition, but there is no parameter list; skipping apparent body e:\gambit-15.1.0\src\libagg\trie_map.imp(74) : error C2072: 'trie_map::findExact' : initialization of a function ..\libagg/agg.h(52) : error C2065: 'AggNumber' : undeclared identifier ..\libagg/agg.h(53) : error C2065: 'AggNumber' : undeclared identifier ..\libagg/agg.h(58) : error C2065: 'AggNumber' : undeclared identifier ..\libagg/agg.h(62) : error C2065: 'AggNumber' : undeclared identifier ..\libagg/agg.h(98) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(98) : error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type ..\libagg/agg.h(98) : error C2955: 'std::vector' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(438) : see declaration of 'std::vector' ..\libagg/agg.h(98) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(98) : error C2065: 'aggpayoff' : undeclared identifier ..\libagg/agg.h(98) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(98) : error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type ..\libagg/agg.h(98) : error C2955: 'std::vector' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(438) : see declaration of 'std::vector' ..\libagg/agg.h(98) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(98) : error C2065: 'aggpayoff' : undeclared identifier ..\libagg/agg.h(161) : error C2146: syntax error : missing ';' before identifier 'getMixedPayoff' ..\libagg/agg.h(161) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(161) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(161) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(161) : warning C4183: 'getMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(162) : error C2061: syntax error : identifier 'AggNumberVector' ..\libagg/agg.h(163) : error C2146: syntax error : missing ';' before identifier 'getV' ..\libagg/agg.h(163) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(163) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(163) : error C2143: syntax error : missing ',' before '&' ..\libagg/agg.h(163) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(163) : warning C4183: 'getV': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(164) : error C2146: syntax error : missing ';' before identifier 'getJ' ..\libagg/agg.h(164) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(164) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(164) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(164) : warning C4183: 'getJ': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(167) : error C2146: syntax error : missing ';' before identifier 'getPurePayoff' ..\libagg/agg.h(167) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(167) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(167) : warning C4183: 'getPurePayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(179) : error C2146: syntax error : missing ';' before identifier 'getSymMixedPayoff' ..\libagg/agg.h(179) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(179) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(179) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(179) : warning C4183: 'getSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(180) : error C2146: syntax error : missing ';' before identifier 'getSymMixedPayoff' ..\libagg/agg.h(180) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(180) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(180) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(180) : warning C4183: 'getSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(181) : error C2061: syntax error : identifier 'AggNumberVector' ..\libagg/agg.h(182) : error C2146: syntax error : missing ';' before identifier 'getKSymMixedPayoff' ..\libagg/agg.h(182) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(182) : error C2065: 'StrategyProfile' : undeclared identifier ..\libagg/agg.h(182) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(182) : warning C4183: 'getKSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(183) : error C2146: syntax error : missing ';' before identifier 'getKSymMixedPayoff' ..\libagg/agg.h(183) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(183) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(183) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(183) : warning C4183: 'getKSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(184) : error C2146: syntax error : missing ';' before identifier 'getKSymMixedPayoff' ..\libagg/agg.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(184) : error C2065: 'StrategyProfile' : undeclared identifier ..\libagg/agg.h(184) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(184) : warning C4183: 'getKSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(185) : error C2146: syntax error : missing ';' before identifier 'getKSymMixedPayoff' ..\libagg/agg.h(185) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(185) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(185) : error C2143: syntax error : missing ',' before '&' ..\libagg/agg.h(185) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(185) : error C2535: 'int agg::getKSymMixedPayoff(int)' : member function already defined or declared ..\libagg/agg.h(183) : see declaration of 'agg::getKSymMixedPayoff' ..\libagg/agg.h(185) : warning C4183: 'getKSymMixedPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(186) : error C2061: syntax error : identifier 'AggNumberVector' ..\libagg/agg.h(193) : error C2146: syntax error : missing ';' before identifier 'getExpectedConfig' ..\libagg/agg.h(193) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(193) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(193) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(201) : warning C4183: 'getExpectedConfig': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(207) : error C2143: syntax error : missing ';' before '&' ..\libagg/agg.h(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(207) : warning C4183: 'getPayoffMap': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(209) : error C2146: syntax error : missing ';' before identifier 'getMaxPayoff' ..\libagg/agg.h(209) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(209) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(209) : warning C4183: 'getMaxPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(210) : error C2146: syntax error : missing ';' before identifier 'getMinPayoff' ..\libagg/agg.h(210) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(210) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(210) : warning C4183: 'getMinPayoff': missing return type; assumed to be a member function returning 'int' ..\libagg/agg.h(237) : error C2327: 'agg::aggpayoff' : is not a type name, static, or enumerator ..\libagg/agg.h(237) : error C2065: 'aggpayoff' : undeclared identifier ..\libagg/agg.h(253) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(253) : error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type ..\libagg/agg.h(253) : error C2955: 'std::vector' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(438) : see declaration of 'std::vector' ..\libagg/agg.h(256) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(256) : error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type ..\libagg/agg.h(256) : error C2955: 'std::vector' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(438) : see declaration of 'std::vector' ..\libagg/agg.h(272) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(281) : error C2065: 'AggNumber' : undeclared identifier ..\libagg/agg.h(300) : error C2653: 'aggpayoff' : is not a class or namespace name ..\libagg/agg.h(300) : error C2065: 'iterator' : undeclared identifier ..\libagg/agg.h(300) : error C2955: 'std::unary_function' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\functional(21) : see declaration of 'std::unary_function' ..\libagg/agg.h(302) : error C2653: 'aggpayoff' : is not a class or namespace name ..\libagg/agg.h(302) : error C2061: syntax error : identifier 'iterator' ..\libagg/agg.h(308) : error C2653: 'aggpayoff' : is not a class or namespace name ..\libagg/agg.h(308) : error C2065: 'iterator' : undeclared identifier ..\libagg/agg.h(308) : error C2955: 'std::unary_function' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\functional(21) : see declaration of 'std::unary_function' ..\libagg/agg.h(310) : error C2653: 'aggpayoff' : is not a class or namespace name ..\libagg/agg.h(310) : error C2061: syntax error : identifier 'iterator' ..\libagg/agg.h(321) : error C2061: syntax error : identifier 'aggpayoff' ..\libagg/agg.h(324) : error C2061: syntax error : identifier 'aggpayoff' ..\libagg/agg.h(328) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(328) : error C3203: 'vector' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type ..\libagg/agg.h(328) : error C2955: 'std::vector' : use of class template requires template argument list C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(438) : see declaration of 'std::vector' ..\libagg/agg.h(335) : error C2065: 'aggdistrib' : undeclared identifier ..\libagg/agg.h(340) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(340) : error C2143: syntax error : missing ',' before '&' ..\libagg/agg.h(343) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ..\libagg/agg.h(343) : error C2143: syntax error : missing ',' before '&' ..\libagg/agg.h(346) : error C2061: syntax error : identifier 'AggNumber' ..\libagg/agg.h(347) : error C2061: syntax error : identifier 'AggNumber' ..\libagg/agg.h(347) : error C2535: 'void agg::doProjection(int,const int)' : member function already defined or declared ..\libagg/agg.h(340) : see declaration of 'agg::doProjection' ..\libagg/agg.h(349) : error C2061: syntax error : identifier 'StrategyProfile' ..\libagg/agg.h(139) : warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data ..\libagg/agg.h(140) : warning C4267: 'return' : conversion from 'size_t' to 'int', possible loss of data ..\libagg/agg.h(169) : error C2663: 'std::vector<_Ty,_Alloc>::at' : 2 overloads have no legal conversion for 'this' pointer ..\libagg/agg.h(169) : error C2228: left of '.size' must have class/struct/union ..\libagg/agg.h(170) : error C2678: binary '[' : no operator found which takes a left-hand operand of type 'std::vector' (or there is no acceptable conversion) C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(758): could be 'vector<_Ty,_Alloc>::_Alloc::const_reference std::vector<_Ty,_Alloc>::operator const' C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\vector(773): or 'vector<_Ty,_Alloc>::_Alloc::reference std::vector<_Ty,_Alloc>::operator ' while trying to match the argument list '(std::vector, int)' ..\libagg/agg.h(194) : error C2065: 'AggNumberVector' : undeclared identifier ..\libagg/agg.h(194) : error C2146: syntax error : missing ';' before identifier 'res' ..\libagg/agg.h(194) : fatal error C1003: error count exceeds 100; stopping compilation error: command 'C:\Users\Tehnrry\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe' failed with exit status 2

tturocy commented 7 years ago

Microsoft C++ is not a supported compiler. In fact building on Windows probably doesn't work, at least not without some doing.

Also, please do open a separate issue with a new question rather than hijacking an unrelated one - it helps keep people from getting confused.

rhalbersma commented 6 years ago

I have been fiddling with making the code compatible with Python3. It requires 4 types of modifications (see e.g. http://python-future.org/compatible_idioms.html):

All in all only the following files need to be modified:

modified:   contrib/scripts/enumpoly/enumpoly.py
modified:   src/python/gambit/games/meanstat.py
modified:   src/python/gambit/gte.py
modified:   src/python/gambit/levelk.py
modified:   src/python/gambit/lib/behav.pxi
modified:   src/python/gambit/lib/mixed.pxi
modified:   src/python/gambit/lib/stratspt.pxi
modified:   src/python/gambit/pctrace.py
modified:   src/python/gambit/profiles.py
modified:   src/python/gambit/qre.py
modified:   src/python/setup.py

With these modifications, the same source builds using both python2.7 and python3.5 on Ubuntu 16.04. The nosetests also continue to pass.

I hesitate to do a pull request as I still have some installation issues:

My understanding of the Python lookup mechanism is insufficient to resolve this. However, if someone would be willing to investigate it, I can do the pull request for the source modifications for Python3.

tturocy commented 6 years ago

Many thanks for your interest in this very useful issue to be dealing with.

I would be available to help support a contribution on this. It would be useful to think first about the most practical way to organise it.

My own preference, based on the 2-to-3 conversions I have been doing with other code of mine, is to use futurize, and also possibly to work on changing one type of change per commit. This should make it somewhat easier to debug - as probably it would be a very good idea to add a few additional tests to exercise the parts of the code where changes are required.

rhalbersma commented 6 years ago

Yeah, futurize is the way to do this properly, making sure python2 users aren’t affected. I’ll also try and put up a Travis CI so that the py2/py3 dependencies are cleanly separated and documented and the tests automated after every commit.

Can’t promise a quick timeframe as this is purely a side project. I was trying to implement counter factual regret (CFR) minimization algorithms, and at first "only" wanted to use Gambit as a check on the equilibrium being computed. Then I realized the whole extensive form infrastructure was too nice not to use for CFR as well. :)

tturocy commented 6 years ago

I'll be happy to have contributions as and when. I am fully booked the next few months but realistically I may be able to allocate some time in July and August to deal with the various pending packaging and Python 2/3 issues that are outstanding.

tturocy commented 5 years ago

Commit b0f989d3 introduces Python3 support. Python 2.7 continues to be supported as well.