Blog: Set-up StarCraft II game and sc2 API (for reinforcement learning) on Ubuntu

Go to the profile of Mels Hakobyan

StarCraft II is a game made for windows and mac and in this post you will see how to set-up and run the game and sc2 API on ubuntu with wine.

There been a lot of hype generated around making AI to play StarCraft II, and DeepMind recently did solve that problem on the level of defeating world’s top players. It’s done using area of Machine Learning called Deep Reinforcement Learning. So if you want to recreate that AI or just simply have fun with Deep RL you need to have a lot of dependencies like pytorch/tensorflow, cuda etc. So it will be ideal if you work on ubuntu, which is probably best suited for such work. By the end of this blog I hope the environment will be up and running on your ubuntu.

So here is the deal you can install wine on ubuntu but you will be have to run your code (which includes sc2 Python package) in wine environment as well. The problems with this are the following — It would be awesome to run your Python code (with a lot of deep learning dependencies and cuda) outside of wine environment and the second one is I have no idea how to do that, cuz I’ve never done that. Let’s begin — open this link and follow the instructions to install StarCraft II game on Ubuntu with Wine, please note that in this answer he tells you how to uninstall PlayOnLinux and install Wine, you can figure it out, just read before copy-paste-ing, he explains everything very clearly. Now if the game is all good, install sc2 by simply running the following command in the terminal (if you don’t have pip installed….well just google it)

pip3 install sc2

Watch this AWESOME tutorial playlist to learn how to interact with the environment. Just copy-paste the python code in the first video in the playlist for now, to be ready to run it later.

Here goes the interesting part, now you have sc2 API and StarCraft II game installed, so the game opens in Wine environment but you want to run sc2 API outside of wine environment so let’s change some source code, shall we??
 Open the sc2 package in python 3 site-packages (for me it’s ~/anaconda3/lib/python3.6/site-packages/sc2), open file with your desired editor (vim for example), and find the following part

This screenshot is a bit different from what you see in your editor, I mean this part (line 7 on screenshot)

“wine”, str(Paths.EXECUTABLE),

This is to call ‘wine’ to execute the game which is in .exe format, just add it to your source code the way you see in the screenshot, now your API uses wine as a wrapper to run the game. Don’t rush to execute the code, we still have to do couple of things.

Now open file in the same directory and find the following part

You can see some commented code and that’s what you see in your source code now (not quite exactly the same cuz I changed it a bit as well, but it’s close). I changed BASEDIR, BINPATH and CWD, look at the ‘Linux’ keys in every mentioned dictionary, if you noticed the value for key ‘Linux’ is the same as ‘WineLinux’ value, so do exactly that, copy from WineLinux value and paste it in place of Linux value (maybe comment the old one tho), just make sure that the paths are correct!! This part is responsible for locating the main package of the game and run it as a back-end for the API. When you run the code from that video, sc2 queries the system you are using and it returns Linux, that’s why I changed everything with Linux key to WineLinux value (path).

Now you will probably be able to run the code from that video on your ubuntu.

I just needed to change one more thing for it to work, if you’re having an error like this

Traceback (most recent call last):
File "", line 12, in <module>
], realtime=False)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 306, in run_game
_host_game(map_settings, players, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asynci o/", line 468, in run_until_complete
return future.result()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 233, in _host_game
result = await _play_game(players[0], client, realtime, portconfig, step_time_limit, game_time_limit, rgb_render_config)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 204, in _play_game
result = await _play_game_ai(client, player_id,, realtime, step_time_limit, game_time_limit)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 92, in _play_game_ai
game_info = await client.get_game_info()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 147, in get_game_info
return GameInfo(result.game_info)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 143, in __init__
self.pathing_grid: PixelMap = PixelMap(self._proto.start_raw.pathing_grid)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/sc2/", line 9, in __init__
assert self.bits_per_pixel % 8 == 0, "Unsupported pixel density"
AssertionError: Unsupported pixel density
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10e443d30>

then follow this instructions

If you are having problems just drop a comment, I am not an expert in this but I can try to help you as much as I can, or just try to figure it out with you.

Source: Artificial Intelligence on Medium

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top