My python scripts run fine from IDLE, but when I try to run them from the command-line, things go wrong. First I had trouble importing pygame, but I added C:\Python27\Lib\site-packages to the PYTHONPATH environment variable and all was well, I thought. However, now when I attempt to run something from the command line, I get this:
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 localize problem; when I try to run another script from the command line, I get this:
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 that syntax is definitely OK...
Pong.py begins like this:
#import sys
import math
import pygame
import time
from pygame.locals import *
# Helper functions
def centerdist(paddletop, balltop):
return balltop - paddletop - 30
# Constants
BLACK = 0, 0, 0
pygame.init()
ntpathinstead ofos.path?ntpathis part of the python stdlib, and works fine for me importing from the interactive interpreter on Win 7. I think theimport siteerror is more important.lib\os.py. He isn't doing it himself.