streamlit: Streamlit failed to hash an object

I am trying to get the DataFrame Demo from streamlit hello to work. I am running this using Anaconda and Python 3.6.

I get the following error in the browser:

Streamlit cannot hash an object of type <class 'os._Environ'>.,

More information: to prevent unexpected behavior, Streamlit tries to detect mutations in cached objects so it can alert the user if needed. However, something went wrong while performing this check.

Please file a bug.

To stop this warning from showing in the meantime, try one of the following:

Preferred: modify your code to avoid using this type of object.
Or add the argument ignore_cache=True to the st.cache decorator.

I get a bunch of additional errors on Streamlit failed to hash an object of type <class 'function'>.,

And then this error blob:

TypeError: object supporting the buffer API required
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/ScriptRunner.py", line 306, in _run_script exec(code, module.__dict__)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 334, in <module> run()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 308, in run demo()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hello.py", line 247, in data_frame_demo df = get_UN_data()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/caching.py", line 544, in wrapped_func return get_or_set_cache()
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/caching.py", line 509, in get_or_set_cache code_hasher.update(func)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hashing.py", line 185, in update self._update(self.hasher, obj, context)
File "/Users/lberndt/anaconda/envs/python3/lib/python3.6/site-packages/streamlit/hashing.py", line 217, in _update hasher.update(b)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

same here, macos, conda, python 3.7.4

Released as 0.48.1

More info: When you st.cache a function, Streamlit’s caching mechanism traverses all function calls inside it to track whether the called function’s body was edited since the cached function was last cached. And Streamlit already ignored “library” functions, since those can be assumed to be unmodified.

However, the way we defined library functions was “functions that were defined outside your current working directory its subfolders”. But this broke whenever your Python environment was placed inside the cwd!

So since version 0.48.1 we define “library function” as any function that was defined:

  • Outside your current working directory its subfolders
  • In a blacklisted folder:
    • The default blacklist is:
      "**/.*",
      "**/anaconda",
      "**/anaconda2",
      "**/anaconda3",
      "**/miniconda",
      "**/miniconda2",
      "**/miniconda3",
      "**/venv",
      "**/virtualenv",
      "**/pyenv",
      
    • Plus anything you specify with the Streamlit config option server.folderWatchBlacklist.

In addition, we also added this explanation to our error message:

This error can occur when your virtual environment lives in the same folder as your project, since that makes it hard for Streamlit to understand which files it should check. If you think that’s what caused this, please add the following to ~/.streamlit/config.toml:

[server]
folderWatchBlacklist = ['foldername']

…where foldername is the relative or absolute path to the folder where you put your virtual environment.


Of course, this still doesn’t solve the underlying problem of why those library functions were not hashable in the first place. We are working on that right now, but since there are a few different cases where things may not be hashable, I’d rather create one bug for each case than have a long-stanging bug with lots of mixed conversations.

Also, for almost everyone who reported this issue, the script that caused the bug was streamlit hello (which we know is 100% hashable!) and the tracebacks provided show the error was always due to library functions not being hashable (which is what we fixed now). So I’ll close this bug now.

Don’t know if I should open a new bug or not, but I have a similar issue with my own code for: <class 'tuple'>, <class 'list'>, <class 'pathlib.PosixPath'>. Downgrading to 0.36 did not solve the issue…

I backed up to v0.46.0 pip install streamlit==0.46.0 and I don’t get that same error. The demo page is a lot different but I was able to run the udacity self driving car tutorial without issue. So this problem seems confined to the latest release.