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

pygambit FileNotFoundError on Windows 10, Python 3.9.7 #305

Closed manuelmontesinos closed 2 years ago

manuelmontesinos commented 2 years ago

Hi there,

I have just installed pygambit on my desktop (the latest version). It runs on Windows 10, and I am using Python 3.9.7. I have tried to follow one of the tutorials to the Python interface on the website of the project (code below). However, when I reach the last line, calling the solver, I get the following error message:

Traceback (most recent call last):
  File "C:\Users\user\pygambit_tutorial.py", line 120, in <module>
    nash = solver.solve(g)
  File "C:\Users\user\Anaconda3\envs\gambit\lib\site-packages\pygambit\nash.py", line 97, in solve
    return self._parse_output(self._call(command_line, game),
  File "C:\Users\user\Anaconda3\envs\gambit\lib\site-packages\pygambit\nash.py", line 55, in _call
    p = subprocess.run(
  File "C:\Users\user\Anaconda3\envs\gambit\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\user\Anaconda3\envs\gambit\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user\Anaconda3\envs\gambit\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

The same code has run through on macOS Monterey 12.3.1, but I would like to know if there is a way to solve this problem on Windows. Have other users experienced any similar problems? Any help is appreciated.

# Import modules
import pygambit
import numpy as np

# Create a new extensive game with no players, and only a root node
g = pygambit.Game.new_tree()

# Check the number of players
print(" ")
print("     Number of players in the new game:")
print(len(g.players))

# Check the title: there is none
print(" ")
print("     Title of the game (there is no title yet):")
print(str(g))

# Add a title. The 'title' attribute provides access to it
print(" ")
print("     Add a title:")
g.title = "A simple poker example"
print(g.title)
print(str(g))

# Add a player to the game by using the 'add()' member of 'players'
print(" ")
print("     Add a player to the game:")
p = g.players.add("Alice")
print(p)

# Each player has a text string stored in the label attribute
print(" ")
print("     Text string of the player:")
print(p.label)

# The players ('Game.players') can be accessed like a Python list. Remember that
# the first element of a list is indexed by 0
print(" ")
print("     Players in the game:")
print(len(g.players))
print(g.players[0])
print(g.players)

#-------------------------------------------------------------------------------
## Building a strategic game
print("-----------------------------------------------------------------------")
print(" ")
print("BUILDING A STRATEGIC GAME")
print(" ")

# Games in strategic form are created using 'Game.new_table()'
g = pygambit.Game.new_table([2,2])
print("     Number of players:")
print(" ")
print(len(g.players))
g.title = "A prisoner's dilemma game"
g.players[0].label = "Alphonse"
g.players[1].label = "Gaston"
print("     Details of the game:")
print(" ")
print(g)

# The 'strategies' collection lists all the strategies available for a player
print("     Available strategies:")
print(" ")
print(g.players[0].strategies)
print(len(g.players[0].strategies))

# Name the strategies
print("     Names of the strategies of Player 1:")
print(" ")
g.players[0].strategies[0].label = "Cooperate"
g.players[0].strategies[1].label = "Defect"
print(g.players[0].strategies)

# Specify the payoffs of each combination of strategies
g[0,0][0] = 8
g[0,0][1] = 8
g[0,1][0] = 2
g[0,1][1] = 10
g[1,0][0] = 10
g[1,0][1] = 2
g[1,1][0] = 5
g[1,1][1] = 5

# Alternatively, one can use 'Game.from_arrays()' in conjuction with numpy arrays
m = np.array([[8,2], [10,5]], dtype=pygambit.Rational)
g = pygambit.Game.from_arrays(m, np.transpose(m))
print("     Details of the game after specifying the payoffs:")
print(" ")
print(g)

# Get the Nash equilibrium in pure strategies by calling command-line tools.
# There is only one equilibrium in pure strategies ('Defect','Defect')
solver = pygambit.nash.ExternalEnumPureSolver()
nash = solver.solve(g)
tturocy commented 2 years ago

Quoting from that page:

The interface to each command-line tool is encapsulated in a class with the word "External" in the name. These operate by creating a subprocess, which calls the corresponding Gambit :ref:`command-line tool <command-line>`. Therefore, a working Gambit installation needs to be in place, with the command-line tools located in the executable search path.

So the error message appears to be correct - it is saying either you do not have these installed, or they are not in $PATH.

As an alternative for enumeration of pure strategies, you can use gambit.nash.enumpure_solve (see that same page).

manuelmontesinos commented 2 years ago

My apologies, I should have seen that. Thank you for your reply.