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

  • Home
  • SEARCH
  • 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 263077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:34:16+00:00 2026-05-11T22:34:16+00:00

I’ve been playing with pyglet . It’s very nice. However, if I run my

  • 0

I’ve been playing with pyglet. It’s very nice. However, if I run my code, which is in an executable file (call it game.py) prefixed with the usual

#!/usr/bin/env python

by doing

./game.py

then it’s a bit clunky. But if I run it with

python -O ./game.py

or

PYTHONOPTIMIZE=1 ./game.py

then its super-smooth.

I’m don’t care much why it runs slow without optimization; pyglet’s documentation mentions that optimizing disables numerous asserts and also OpenGL’s error checking, and I’m happy to leave it at that.

My question is: how do people distributing Python code make sure the end users (with zero interest in debugging or modifying the code) run the optimized version of the code. Surely there’s some better way than just telling people to make sure they use optimization in the release notes (which they probably won’t read anyway) ?

On Linux I can easily provide a ./game script to run the file for end users:

#!/bin/sh
PYTHONOPTIMIZE=1 ./game.py $*

but that’s not very cross-platform.

I have an idea I ought to be able to change the #! line to

#!/usr/bin/env PYTHONOPTIMIZE=1 python

or

#!/usr/bin/env python -O

but those don’t seem to work as expected, and I’m not sure what they’d do on Windows.

Is there some way of controlling optimization from within the code I’m unaware of ?
Something like:

  import runtime
  runtime.optimize(True)

What’s considered best-practice in this area by people shipping multi-platform python code ?

  • 1 1 Answer
  • 1 View
  • 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-05-11T22:34:17+00:00Added an answer on May 11, 2026 at 10:34 pm

    “On Linux I can easily provide a ./game script to run the file for end users:”

    Correct.

    “but that’s not very cross-platform.”

    Half-correct. There are exactly two shell languages that matter. Standard Linux “sh” and Non-standard Windows “bat” (a/k/a cmd.exe) and that’s all there is nowadays. [When I was a kid, there was Open VMS DCL and Data General’s weird shell language and RSX-11 and all kinds of great stuff. Thank God for the Posix standard.]

    game.sh

    python -O game.py
    

    game.bat

    python -O game.py
    

    Interestingly the files are the same, only the extension (and the file format) had to be changed to make the various OS’s happy.

    If you want true one-size-fits-all cross platform, you have to remember that Python is a shell language. This kind of thing works, also.

    game-startup.py

    import subprocess
    subprocess.Popen( "python -O game.py" )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.