"Python programming that you can enjoy learning while making games" http://nextpublishing.jp/book/8501.html I bought this book the other day, but for some reason the key input was executed on the terminal or in the editor, and the essential game did not work at all.
After investigating, it seems that it works normally if pyenv is uninstalled and python3 is reinstalled from the official installer. There seems to be a case where it was solved by changing the version of pygame. https://stackoverflow.com/questions/2718897/mac-os-x-pygame-input-goes-to-terminal-instead-of-python
In my case, maybe because I'm using Anaconda, changing the version of pygame didn't work. At the same time, I'm using Python3 for another work, so I want to use anaconda too ... So first install pyenv. (pyenv is a tool that allows you to easily switch between python versions.) I referred to the following site for how to install pyenv. Building an environment with pyenv and virtualenv
After that, use pyenv to check the available version.
$pyenv install --list
2.7.11
2.7.12
2.7.13 ← These guys
3.0.1
3.1
3.1.1
You will see a lot of lists here, so install python2 from the above part.
$ pyenv install 2.7.13
And execute.
You can check if it was installed by typing $ pyenv versions
.
After that, move to the directory where the game is created using pygame, enter $ pyenv local 2.7.13
, and execute.
At this time, you can apply python2 to the whole by typing $ pyenv global -.-.-.
, but since python2 is not needed anymore, apply it only to the target directory.
At this time, even though I applied python2 to local, python2 was not reflected for some reason and it was still Python 3.6.1 | Anaconda 4.4.0, but once I restarted it was solved in my case. If you still can't fix it, you may want to refer to the following. What to do when Python does not switch from the System version in pyenv
With the above processing, in the case of the author, key input is possible.
By the way, when operating in the Python2 environment, most of the functions work without problems, Functions such as map, reduce, and filter do not need to be enclosed in list () etc. If you delete this part, it will work without any problem.
Recommended Posts