☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Pickling problem - Bokeh server

Community Support
Nikoloz_Mamisashvili
Nikoloz_Mamisashvili

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.

I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

⌁   Link to post
Bryan
Bryan

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

"""
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.
"""

The only potential solution I can imagine is to move *all* code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for __class__. However, you will simply have to try and see, I can't say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

···

On Feb 21, 2019, at 00:05, nikusha37@gmail.com wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named 'bk_script_1001'.

I think it is because the __class__ method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

⌁   Link to post
Nikoloz_Mamisashvili
Nikoloz_Mamisashvili

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

···

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, niku...@gmail.com wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
Bryan
Bryan

Hi,

You should use a “Directory Style” organization for the app then you can import normally from the directory with the main.py

Thanks,

Bryan

···

On Feb 21, 2019, at 03:05, nikusha37@gmail.com wrote:

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, niku...@gmail.com wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/efdd990e-169b-4f56-822b-fc195a582b4e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post
Nikoloz_Mamisashvili
Nikoloz_Mamisashvili

it works.

thank you very much.

···

On Sun, Feb 24, 2019, 20:43 Bryan Van de ven bryan@bokeh.org wrote:

Hi,

You should use a “Directory Style” organization for the app then you can import normally from the directory with the main.py

Thanks,

Bryan

On Feb 21, 2019, at 03:05, nikusha37@gmail.com wrote:

Thank you very much Bryan.

I tried to create new file called classes.py in mydir.

In classes.py I put all the code for pickling but then the problem is that I was not able to import from that file.

It gave me an exception while importing because I think when I use bokeh serve command main.py can not directly import other modules from the same directory. Is it right?

On Thursday, February 21, 2019 at 12:23:06 PM UTC+4, Bryan Van de ven wrote:

Hi,

Bokeh dynamically creates module new module objects every time a user session is initiated, and the app code is run inside that new module for isolation. If you are saving/reading between different sessions. then the modules will necessarily be different. The pickle docs suggest that this is this is not permissible:

“”"
pickle can save and restore class instances transparently, however the class definition must be importable and live in the same module as when the object was stored.

“”"

The only potential solution I can imagine is to move all code for loading and saving pickles to functions in a separate module, completely outside the Bokeh app script, that the app script imports. That might coax Python to use that (external, fixed) module instead of the dynamic Bokeh app module for class. However, you will simply have to try and see, I can’t say for certain. Otherwise, here are may other common serialization methods (if you want to continue using Bokeh), or a handful of other potential visualization tools (if you want to continue to use pickle).

Thanks,

Bryan

On Feb 21, 2019, at 00:05, niku...@gmail.com wrote:

Hello friends,

I am using bokeh server for my application.

I use command: bokeh serve mydir

in my dir there is main.py file in which I have defined DataCollector class.
I need to pickle this class and read it periodically but under bokeh serve it gives me an error while deserializing: ModuleNotFoundError: No module named ‘bk_script_1001’.

I think it is because the class method of DataCollector gets value of bk_script_1001.DataCollector while running with bokeh server.

Can anyone help me in avoiding this ModuleNotFoundError?

Thank you very much.

–
You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1047b0-4095-457b-b468-6fc78331a0e5%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/efdd990e-169b-4f56-822b-fc195a582b4e%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

–

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/Y5o602X1w2U/unsubscribe.

To unsubscribe from this group and all its topics, send an email to bokeh+unsubscribe@continuum.io.

To post to this group, send email to bokeh@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/C0E6A5F9-B774-45B6-B548-6B301A90709D%40anaconda.com.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

⌁   Link to post

End of archived discussion · Replies are disabled