7

I am new to Python and am totally lost as to where to even start to get this done.

I have written many small modules (a toolset for maya) that need to be compiled into on single .pyc file. Is there a module that just does this? Or can you tell me where to go to start? A tutorial? I don't even know what terms to look for.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user12294
  • 91
  • 1
  • 2
  • 3
    What makes you think you need to do this? – Daniel Roseman Jul 10 '13 at 16:23
  • 1
    Because I dont want to have to load 50 different python files into Maya. Wouldnt it be better to be able to just add one and have access to all? – user12294 Jul 10 '13 at 16:28
  • 1
    No, its better to have 50 files in one folder. Loading 50 different files is no more complex than loading 1, its just one call either way. However form a management, extension and usage point of view its better to have 50 files. If on the other hand you want to obfuscate your code do not use python, use c++ instead. However python allows you to zip up the folder (and call it an egg), so the user only sees one folder, its still 50 separate files. – joojaa Jul 11 '13 at 11:09
  • 1
    This is a completely legit question ( and one that get's discussed a lot - see links in my answer). I don't think the downvotes are warrented – theodox Jul 15 '13 at 23:13
  • 1
    That's a legit issue. For instance when deploying a plugin for a python scripted app (such as Maya, Rhino...) in an installer, it's much more simple to have one file. Especially if you build the installer with WiX. – galinette Nov 21 '13 at 16:52

2 Answers2

1

You don't even need to make an egg, you can just zip up your files and put the zip file onto your python path. Maya's version of python includes the zipimport module by default so it 'just works' as long as maya can find your zip file.

Here are some discussions of the whole topic of tools distribution you might find useful:

http://tech-artists.org/forum/showthread.php?3271-Distribution-techniques-for-external-Python-tools&highlight=distribute

http://tech-artists.org/forum/showthread.php?3987-Maya-GitHub-and-Script-Paths-for-Mel-and-Python-How-Would-You-Do-It&highlight=distribute

http://tech-artists.org/forum/showthread.php?3752-Best-Way-to-Share-Your-Scripts&highlight=distribution

Mihai Oprea
  • 2,051
  • 3
  • 21
  • 39
theodox
  • 12,028
  • 3
  • 23
  • 36
0

The compileall module, present in the standard library, will compile all files in a directory, but it will still not generate a single .pyc file. An example of its usage is also given at effbot.org. I don't know if it's possible at all to create a single pyc file out of multiple modules.

However, my guess is that you are looking into creating a python egg, which does make a single file out of a series of files grouped together in a package, which is what you want, I think.

Community
  • 1
  • 1
Oliver W.
  • 13,169
  • 3
  • 37
  • 50