-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_plotly_issues.py
More file actions
153 lines (121 loc) Β· 4.59 KB
/
fix_plotly_issues.py
File metadata and controls
153 lines (121 loc) Β· 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
Troubleshooting script for Plotly installation and compatibility issues
"""
import subprocess
import sys
import importlib
import os
def check_python_version():
"""Check Python version compatibility"""
print("π Checking Python version...")
version = sys.version_info
print(f"Python version: {version.major}.{version.minor}.{version.micro}")
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("β Python 3.8 or higher is required")
return False
else:
print("β
Python version is compatible")
return True
def check_plotly_installation():
"""Check if Plotly is properly installed"""
print("\nπ Checking Plotly installation...")
try:
import plotly
print(f"β
Plotly version: {plotly.__version__}")
# Test basic Plotly functionality
import plotly.graph_objects as go
import plotly.express as px
# Create a simple test figure
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3]))
print("β
Plotly basic functionality working")
return True
except ImportError as e:
print(f"β Plotly import error: {e}")
return False
except Exception as e:
print(f"β Plotly functionality error: {e}")
return False
def check_streamlit_plotly_integration():
"""Check Streamlit-Plotly integration"""
print("\nπ Checking Streamlit-Plotly integration...")
try:
import streamlit as st
print(f"β
Streamlit version: {st.__version__}")
# Check if streamlit can handle plotly
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3]))
print("β
Streamlit-Plotly integration should work")
return True
except Exception as e:
print(f"β Streamlit-Plotly integration error: {e}")
return False
def install_fixes():
"""Install required packages with fixes"""
print("\nπ§ Installing fixes...")
packages_to_install = [
"plotly>=5.0.0",
"streamlit>=1.28.0",
"pandas>=1.5.0",
"numpy>=1.21.0"
]
for package in packages_to_install:
try:
print(f"Installing {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", package])
print(f"β
{package} installed successfully")
except subprocess.CalledProcessError as e:
print(f"β Failed to install {package}: {e}")
return False
return True
def create_minimal_test():
"""Create a minimal test to verify everything works"""
print("\nπ§ͺ Creating minimal test...")
test_code = '''
import streamlit as st
import plotly.graph_objects as go
import plotly.express as px
st.title("Plotly Test")
st.write("If you can see this and the chart below, Plotly is working!")
# Create a simple chart
fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 2, 3], title="Test Chart")
st.plotly_chart(fig)
st.success("β
Plotly is working correctly!")
'''
with open("plotly_test.py", "w") as f:
f.write(test_code)
print("β
Created plotly_test.py")
print("Run 'streamlit run plotly_test.py' to test Plotly functionality")
def main():
"""Main troubleshooting function"""
print("π Plotly Troubleshooting Script")
print("=" * 50)
# Check Python version
if not check_python_version():
print("\nβ Please upgrade Python to version 3.8 or higher")
return
# Check Plotly installation
if not check_plotly_installation():
print("\nπ§ Attempting to fix Plotly installation...")
if install_fixes():
print("β
Installation fixes applied. Please restart your application.")
else:
print("β Could not fix installation. Please manually install packages.")
return
# Check Streamlit integration
if not check_streamlit_plotly_integration():
print("\nπ§ Attempting to fix Streamlit integration...")
install_fixes()
return
# Create test file
create_minimal_test()
print("\n" + "=" * 50)
print("β
All checks passed! Plotly should be working correctly.")
print("\nIf you're still having issues:")
print("1. Restart your terminal/command prompt")
print("2. Run: pip install --upgrade plotly streamlit")
print("3. Run: streamlit run plotly_test.py")
print("4. If that works, try: streamlit run app.py")
if __name__ == "__main__":
main()