My python scripts work fine with IDLE, but when I try to run them from the command line, everything goes wrong. At first I was not able to import pygame, but I added C: \ Python27 \ Lib \ site-packages to the PYTHONPATH environment variable, and everything was fine, I thought. However, now when I try to start something from the command line, I get the following:
C:\Users\Ian Sinke\Documents\Pong>python pong.py
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "pong.py", line 3, in ?
import pygame
File "C:\Python27\Lib\site-packages\pygame\__init__.py", line 27, in ?
import sys, os, string
File "C:\Python27\Lib\os.py", line 63, in ?
import ntpath as path
File "C:\Python27\Lib\ntpath.py", line 401
backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.')
^
SyntaxError: invalid syntax
Any ideas?
This is not a localization problem; when I try to run another script from the command line, I get the following:
C:\Users\Ian Sinke\Documents>python app.py
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "app.py", line 4, in ?
import urllib2
File "C:\Python27\Lib\urllib2.py", line 92, in ?
import base64
File "C:\Python27\Lib\base64.py", line 346
with open(args[0], 'rb') as f:
^
SyntaxError: invalid syntax
and this syntax is definitely ...
Pong.py starts as follows:
import math
import pygame
import time
from pygame.locals import *
def centerdist(paddletop, balltop):
return balltop - paddletop - 30
BLACK = 0, 0, 0
pygame.init()