0

I've made a system of distributing tools using a zip. The tools inside the zip seem to only like to run from pyc. One of my animators is using Maya 2013, which has an older version of python (2.6.4). I get a Magic Numbers error when he tries to run my files.

How can I compile my scripts to an older version of python?

  • Related: [What's the bad magic number error?](http://stackoverflow.com/questions/514371/whats-the-bad-magic-number-error). Maybe check the accepted answer. Remove all .pyc files and then try executing your code in Maya 2013. EDIT: you have access to .py files right? – DrHaze Jan 28 '16 at 15:08
  • Magic Number is the error you get when you compile the code in a newer version than the program running it. So in this case it's compiles in Maya 2.7.3, but the animator is using maya 2013, which has 2.6.4. I'll try the only py. I had try py and pyc, but that didn't work. – Colin Knueppel Jan 28 '16 at 15:16
  • If deleting the .pyc files fixes your issue, you might want to add `sys.dont_write_bytecode = True`(added in Python 2.6) at the beginning of your scripts to avoid generating bytecode. – DrHaze Jan 28 '16 at 15:25

1 Answers1

0

If you're distributing pyc files you'll need to 'compile' them for the python major version you are targeting by running py_compile from an interpreter that's on the right version. You can probably do this using a 2.6.4 intepreter without actually running maya so if you don't have the same maya version but can grab an interpreter it will create 2.6.4 compatible pycs.

However you should also be able to distribute zipped .py files instead, which should be version independent (the main gotchas will be that 2.7 supports a few features, like dict comprehensions and OrderedDict, that 2.6 does not have).

The biggest wrinkle will be binaries: any code that relies on .so or .pyd modules probably won't work between intepreter versions. I usually end up having to pack version-specific binaries into the zip and extract them at startup time.

theodox
  • 12,028
  • 3
  • 23
  • 36