For example:
// file foo
def my_func():
print("foo!")
// file bar
class Bar:
def __init__(self):
pass
def hello():
import foo.my_func
my_func()
import dill
dill.dump(Bar(), open("bar.dpkl",mode='wb+'))
$: python3 -m venv foobar
$: source activate foobar/bin/activate
(foobar) $: python3
>>> import dill
>>> obj = dill.load(open("bar.dpkl",mode='rb')) # just fine
>>> obj.hello()
foo!
But, suppose I throw in a twist:
class Bar:
def __init__(self):
import numpy
Now,
>>> obj = dll.load(open("bar.dpkl",mode='rb'))
ModuleNotFoundError: No module named 'numpy'
It appears as if the linked C
-binaries are not bundled up in the pickle
file. However, if the code is genuine, native python
code, the pickle
file output by dill
is essentially a dynamic archive.
Is there any way to extend this dynamic archive behavior to include the libraries like numpy
et al.? Or must these sort of C
+ python
-shell libraries always be installed in the executing python
environment?
Basically, I think the thing I am asking for is a pythonic version of a jar
that can be generated straight from python
code: is this possible? Or is a container with requisite dependencies the jar
I am looking for?