Repository: streamlit/streamlit

Issue:
DataFrame demo: Streamlit failed to hash an object of type <class 'code'>
# Summary
Running the DataFrame demo on a fresh install results in `Streamlit failed to hash an object of type <class 'code'>`

# Steps to reproduce
What are the steps we should take to reproduce the bug:
1. $ `pip install streamlit`
2. $ `streamlit hello`
3. In browser select `DataFrame Demo`

## Expected behavior:

See the demo

## Actual behavior:

Stacktrace shown in browser app

```
NameError: name 'urllib' is not defined
File "/Users/kmatt/anaconda3/lib/python3.7/site-packages/streamlit/ScriptRunner.py", line 306, in _run_script exec(code, module.__dict__)
File "/Users/kmatt/anaconda3/lib/python3.7/site-packages/streamlit/hello.py", line 329, in <module> run()
File "/Users/kmatt/anaconda3/lib/python3.7/site-packages/streamlit/hello.py", line 303, in run demo()
File "/Users/kmatt/anaconda3/lib/python3.7/site-packages/streamlit/hello.py", line 243, in data_frame_demo except urllib.error.URLError:
```


# Debug info
- Streamlit version: `Streamlit, version 0.47.1`
- Python version: `Python 3.7.3`
- Using Conda
- OS version: macOS 10.14.5
- Browser version: Chrome 77.0.3865.90




Discussion:
Similar result with a fresh Python 3.6 environment:

```
conda create --name streamlit python=3.6
conda activate streamlit
pip install streamlit
streamlit hello
```

```
NameError: name 'urllib' is not defined
File "/Users/kmatt/anaconda3/envs/streamlit/lib/python3.6/site-packages/streamlit/ScriptRunner.py", line 306, in _run_script exec(code, module.__dict__)
File "/Users/kmatt/anaconda3/envs/streamlit/lib/python3.6/site-packages/streamlit/hello.py", line 329, in <module> run()
File "/Users/kmatt/anaconda3/envs/streamlit/lib/python3.6/site-packages/streamlit/hello.py", line 303, in run demo()
File "/Users/kmatt/anaconda3/envs/streamlit/lib/python3.6/site-packages/streamlit/hello.py", line 243, in data_frame_demo except urllib.error.URLError:
```
Demo functions in a Python 2.7 env.
Thanks for the bug report! This is very odd... I'm pretty sure urllib is [a standard Python library](https://docs.python.org/3/library/urllib.html).

I'm trying to repro now. Will get back to you.
I don't see an `import urllib` in this file:

https://github.com/streamlit/streamlit/blob/0.47.1/lib/streamlit/hello.py

basically, it looks like you're missing an import statement, but the code path that requires it only runs in the "no internet connection" case
Thanks! Yeah, we're getting a fix together to push out imminently -

Thanks for the heads up, @kmatt and @joelgrus!

Resolving patch:
diff --git a/lib/streamlit/hello.py b/lib/streamlit/hello.py
--- a/lib/streamlit/hello.py
+++ b/lib/streamlit/hello.py
@@ -87,48 +87,52 @@ def mapping_demo():
     to display geospatial data.
     """
     import pandas as pd
-    import copy, os
+    import os
 
     @st.cache
     def from_data_file(filename):
         GITHUB_DATA = "https://raw.githubusercontent.com/streamlit/streamlit/develop/examples/"
         return pd.read_json(os.path.join(GITHUB_DATA, "data", filename))
 
-    ALL_LAYERS = {
-        "Bike Rentals": {
-            "type": "HexagonLayer",
-            "data": from_data_file("bike_rental_stats.json"),
-            "radius": 200,
-            "elevationScale": 4,
-            "elevationRange": [0, 1000],
-            "pickable": True,
-            "extruded": True,
-        },
-        "Bart Stop Exits": {
-            "type": "ScatterplotLayer",
-            "data": from_data_file("bart_stop_stats.json"),
-            "radiusScale": 0.05,
-            "getRadius": "exits",
-        },
-        "Bart Stop Names": {
-            "type": "TextLayer",
-            "data": from_data_file("bart_stop_stats.json"),
-            "getText": "name",
-            "getColor": [0, 0, 0, 200],
-            "getSize": 15,
-        },
-        "Outbound Flow": {
-            "type": "ArcLayer",
-            "data": from_data_file("bart_path_stats.json"),
-            "pickable": True,
-            "autoHighlight": True,
-            "getStrokeWidth": 10,
-            "widthScale": 0.0001,
-            "getWidth": "outbound",
-            "widthMinPixels": 3,
-            "widthMaxPixels": 30,
+    try:
+        ALL_LAYERS = {
+            "Bike Rentals": {
+                "type": "HexagonLayer",
+                "data": from_data_file("bike_rental_stats.json"),
+                "radius": 200,
+                "elevationScale": 4,
+                "elevationRange": [0, 1000],
+                "pickable": True,
+                "extruded": True,
+            },
+            "Bart Stop Exits": {
+                "type": "ScatterplotLayer",
+                "data": from_data_file("bart_stop_stats.json"),
+                "radiusScale": 0.05,
+                "getRadius": "exits",
+            },
+            "Bart Stop Names": {
+                "type": "TextLayer",
+                "data": from_data_file("bart_stop_stats.json"),
+                "getText": "name",
+                "getColor": [0, 0, 0, 200],
+                "getSize": 15,
+            },
+            "Outbound Flow": {
+                "type": "ArcLayer",
+                "data": from_data_file("bart_path_stats.json"),
+                "pickable": True,
+                "autoHighlight": True,
+                "getStrokeWidth": 10,
+                "widthScale": 0.0001,
+                "getWidth": "outbound",
+                "widthMinPixels": 3,
+                "widthMaxPixels": 30,
+            }
         }
-    }
+    except urllib.error.URLError:
+        st.error("Connection Error. This demo requires internet access")
+        return
 
     st.sidebar.markdown('### Map Layers')
     selected_layers = [layer for layer_name, layer in ALL_LAYERS.items()


Test patch: