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 8863037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:52:32+00:00 2026-06-14T15:52:32+00:00

I have a simple python script, which imports various other modules I’ve written (and

  • 0

I have a simple python script, which imports various other modules I’ve written (and so on). Due to my environment, my PYTHONPATH is quite long. I’m also using Python 2.4.

What I need to do is somehow package up my script and all the dependencies that aren’t part of the standard python, so that I can email a single file to another system where I want to execute it. I know the target version of python is the same, but it’s on linux where I’m on Windows. Otherwise I’d just use py2exe.

Ideally I’d like to send a .py file that somehow embeds all the required modules, but I’d settle for automatically building a zip I can just unzip, with the required modules all in a single directory.

I’ve had a look at various packaging solutions, but I can’t seem to find a suitable way of doing this. Have I missed something?

[edit] I appear to be quite unclear in what I’m after. I’m basically looking for something like py2exe that will produce a single file (or 2 files) from a given python script, automatically including all the imported modules.

For example, if I have the following two files:

[\foo\module.py]
def example():
    print "Hello"

[\bar\program.py]
import module
module.example()

And I run:

cd \bar
set PYTHONPATH=\foo
program.py

Then it will work. What I want is to be able to say:

magic program.py

and end up with a single file, or possibly a file and a zip, that I can then copy to linux and run. I don’t want to be installing my modules on the target linux system.

  • 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-14T15:52:33+00:00Added an answer on June 14, 2026 at 3:52 pm

    I’ve come up with a solution involving modulefinder, the compiler, and the zip function that works well. Unfortunately I can’t paste a working program here as it’s intermingled with other irrelevant code, but here are some snippets:

    zipfile = ZipFile(os.path.join(dest_dir, zip_name), 'w', ZIP_DEFLATED)
    sys.path.insert(0, '.')
    finder = ModuleFinder()
    finder.run_script(source_name)
    
    for name, mod in finder.modules.iteritems():
        filename = mod.__file__
        if filename is None:
            continue
        if "python" in filename.lower():
            continue
    
        subprocess.call('"%s" -OO -m py_compile "%s"' % (python_exe, filename))
    
        zipfile.write(filename, dest_path)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple python script that should scan a text file, which
I have a simple python script which calls 6 threads and for some reason
I have a python script which outputs lots of data, sample is as below.
I have a simple python script (say, simple.py) , like a = 5 b
I have a simple Python script that uses a signal handler for Ctl-C. If
I have a simple Python script that uses the socket module to send a
I have the following simple python test script that uses Suds to call a
I have some questions about the performance of this simple python script: import sys,
I have a python script on a vps that I run a simple command
I have written this short script (which I've stripped away some minor detail for

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.