Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7921667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:40:18+00:00 2026-06-03T16:40:18+00:00

My python scripts run fine from IDLE, but when I try to run them

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:40:20+00:00Added an answer on June 3, 2026 at 4:40 pm

    This sounds to me like you’ve got two different versions of Python on your computer. One is a more recent version that accepts Python’s version of the ternary expression, and one is an older version. When you use IDLE, the newer version is called. When you use the command line, the older version is called. You can confirm or disprove this hypothesis by running python -V from the command line.

    To elaborate, support for conditional expressions was added in Python 2.5. So when you modified PYTHONPATH, you wound up running a newer python file (from 2.7, it sounds like) with an older version of python (2.4, according to your test).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible for TextMate to run Python scripts in IDLE instead of internally
I just setup PortablePython on my system, so I can run python scripts from
I have python script that works fine but only when run as stand-alone, while
I can run this command from the command line without any problem (the validation
I'm trying to run Python scripts using Xcode's User Scripts menu. The issue I'm
I have a web service to which users upload python scripts that are run
So I have to run some python scripts on a cluster with machines for
Is it possible to create an environment to safely run arbitrary Python scripts under
I want to run a python script from within another. By within I mean
I have a python script on a vps that I run a simple command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.