Processing when the key input of Python pygame does not go well.

environment

  1. Mac OS X Yosemite ver.10.10.5
  2. Python 3.6.1 | Using Anaconda 4.4.0 (x86_64)

Reference book

"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.

Solution case

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

Solution

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.

Postscript

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

Processing when the key input of Python pygame does not go well.
When incrementing the value of a key that does not exist
Key input that does not wait for key input in Python
When cv2.VideCapture (aviname) does not read well
Python> Python does not include the last offset
The story of blackjack A processing (python)
Example of what to do when the sample script does not work (OpenCV-Python)
About the problem that the python version of Google App Engine does not mesh
View the result of geometry processing in Python
Image processing? The story of starting Python for
Addition of fixed processing when starting python interpreter
What to do when python3 type venv does not work well on Raspberry Pi
Solution when Linux does not recognize the built-in camera
Examine the close processing of Python dataset (SQLAlchemy wrapper)
Not being aware of the contents of the data in python
Check when the version does not switch with pyenv
Key input in Python
the zen of Python
Key input in Python
Various processing of Python
Parallel processing of Python joblib does not work in uWSGI environment. How to process in parallel on uWSGI?
I don't want an if document when processing after confirming the existence of the dict key
[Python beginner] Variables and scope inside the function (when the processing inside the function is reflected outside the function and when it is not reflected)
Grep so that grep does not appear at the time of grep
Python error support note: "... does not support argument 0 of type float ..."
Check when the Docker container does not connect to the Internet
The websocket of toio (nodejs) and python / websocket do not connect.
[Python] Tensorflow 2.0 did not support Python 3.8, so the story of downgrading Python
[VSCode] unable to import'google.cloud' What to do when pylint (import-error) does not recognize the Python import statement
python3 Measure the processing speed.
Towards the retirement of Python2
About the ease of Python
Python version does not switch
About the features of Python
The Power of Pandas: Python
The story that the version of python 3.7.7 was not adapted to Heroku
The story of not being able to run pygame with pycharm
Count the number of Thai and Arabic characters well in Python
How to judge that the cross key is input in Python3
Solution when background-cover of Linux version VS Code does not work
Tkinter canvas (window) does not start when running Python 3.7.4 with Atom
A function that measures the processing time of a method in python
The story of the release work of the application that Google does not tell
The problem that the version of Vue CLI did not go up
Build Python environment on Ubuntu (when pip is not the default)
When the program pip installed on Mac / Marvericks does not work
A super beginner who does not know the basics of Python tried to graph the stock price of GAFA