Import the entire Python standard library

I need a way to import the entire standard Python library into my program.

Although this may seem like a bad idea, I want to do it, so py2exe will pack the entire standard library with my program, so my users can import it from the shell that I give them.

Is there an easy way to do this?

Bonus points: I would prefer this action to NOT import packages that I installed into site packages that did not ship with Python. However, this is not critical.

+4
source share
2 answers

Hey, I just thought about something: I only need a list of all the modules in stdlib, and then I will automatically create a Python script that imports each of them โ€œmanuallyโ€, for example:

import re import math import time # ... 

And then turn it on with my program.

So now I need to easily format the list of all modules / packages in stdlib. Now, how do I get this?

UPDATE:

I got a list like this: I installed Python 2.6 on a virtual machine, then ran into IDLE:

 import pkgutil stuff = [thing[1] for thing in pkgutil.iter_modules()] stuff.sort() # To make it easy to look through print(stuff) 

Then copy the output paste into my IDE and make a little script to write:

 if False: import re import email import time # ... 

To the Python module that I import into my program.

It works! py2exe packs the entire stdlib.

UPDATE:

I created a package that does this. I would download it here, but since I donโ€™t see the download button, you can get it from the project folder:

http://github.com/cool-RR/PythonTurtle/tree/master

In the src folder, the package is called almostimportstdlib and it is documented.

+2
source

I created a zip file from the entire standard Python library, and then added it to sys.path when the program started.

You can see the sources here (abandoned project)

+1
source

All Articles