我的 python 脚本在 IDLE 中运行良好,但是当我尝试从命令行运行它们时,出现了问题。首先我在导入 pygame 时遇到了麻烦,但我将 C:\Python27\Lib\site-packages 添加到 PYTHONPATH 环境变量中,一切都很好,我想。但是,现在当我尝试从命令行运行某些东西时,我得到了这个:
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
有任何想法吗?
这不是本地化问题;当我尝试从命令行运行另一个脚本时,我得到了这个:
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
那语法肯定没问题...
Pong.py 的开头是这样的:
#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()