1

Here is the problem...

I'm writing very small plugin for Blender, I have 10 python scripts, they parsing different file formats by using command-line, and I have a Main Python script to run all other scripts with proper commands...

for example, "Main.py" include:

txt2cfg.py -inFile -outFile...
ma2lxo.py -inFile -outFile...

Blender already include Python, so I can run "Main.py" from Blender, But I need it to work with both PC and MAC, and also doesn't require Python installation, so I can't use:

  • execfile(' txt2cfg.py -inFile -outFile ')
  • os.system(' ma2lxo.py -inFile -outFile ')
  • or even import subprocess

because they required Python installation in order to run *.py files.

Sorry for language

Thanks

3
  • "and also doesn't require Python installation". Bad idea. Just install Python. Life is much simpler. Commented Aug 31, 2011 at 20:13
  • If you can't push anyone to install the platform, how can you push anyone to run your application? Commented Aug 31, 2011 at 20:21
  • As friendly as possible means simple, right? That means Python is required and your main script simply does import to incorporate the 10 other processes. That's simple. Commented Aug 31, 2011 at 20:25

3 Answers 3

4

If you really need to execute a python script in a new process and you don't know where the interpreter you want is located then use the sys module to help out.

import sys
import subprocess

subprocess.Popen((sys.executable, "script.py"))

Though importing the module (dynamically if need be) and then running its main method in another script is probably a better idea.

Sign up to request clarification or add additional context in comments.

Comments

3

for example, "Main.py" include:

txt2cfg.py -inFile -outFile... ma2lxo.py -inFile -outFile...

Two things.

  1. Each other script needs a main() function and a "main-import switch". See http://docs.python.org/tutorial/modules.html#executing-modules-as-scripts for hints on how this must look.

  2. Import and execute the other scripts.

    import txt2cfg
    import ma2lxo
    txt2cfg.main( inFile, outFile )
    ma2lxo.main( inFile, outFile )
    

This is the simplest way to do things.

Comments

1

Two options:

  1. Use py2exe to bundle the interpreter with the scripts.
  2. Import the modules and call the functions automatically.

2 Comments

Haha sorry! But you could use py2exe and py2app!
Yup! No problem! Although I haven't used it much, it is possible that py2app might require you to have a mac then compile on that. FYI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.