问题
This is the third time pygame/livewires has led me to this website, and let it be the last! After installing 'Python 3.1.1' for the book, 'Python Programming for the Absolute Beginner', I installed pygame and then livewires. I tested Pygame by entering
import pygame
And it worked by properly running it. However, when I tested livewires with 'from livewires import games, colors
it produced no errors in IDLE, but did produce an error when I properly ran it. The error flicked away so quick I couldn't see it, but I recorded it and paused it just at the right time and got this error:
Traceback (most recent call last):
File "C:\Python31\TEST", line 1, in , <module>
from livewires import games, colors
File "C:\Python34\lib\site-packages\livewires\games.py", line 57, in <module>
import pygame, pygame.image, pygame.nixer, pygame.font, pygame.transform
ImportError: No module named 'pygame.image'
Something I did notice about this is it says Python34, another version I have, in the error not Python31, though the problem may be somewhere else completely. Please not that it is not my spelling of 'color' that is messing this up. The guy who made the book and bundled it with this special version of livewires seems to have made it spelled 'colors' and not 'colours'. I've tried both and using the British spelling (the one I normally use) just causes an error to appear in IDLE as well.
Please help, hopefully, for the last time. Thanks in advance, Harry.
回答1:
You should set your PATH and sys.path(the path modules are imported from) pointing to the same version of Python. Currently Python 3.1 executable is in your path, but it is using the modules of Python 3.4.
- To fix your python executable path: https://docs.python.org/2/using/windows.html#finding-the-python-executable
- To fix your sys.path: https://docs.python.org/2/using/windows.html#finding-modules
And one way to have isolated versions of python on your system is using virtual-env: https://virtualenv.pypa.io/en/latest/
来源:https://stackoverflow.com/questions/29802629/python-livewires-console-error