I have some code in Python (Jupyter Notebooks in my Anaconda environment). The file is called myFile.py:
import math
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
import plotly
DF = pd.read_csv('My CSV data file path')
myCol = DF['Temp'].value_counts(normalize = True)
fig = plotly.express.bar(myCol)
fig.show()
My code runs exactly as expected in python.
I used pyinstaller to successfully convert this code into an exe file (pyinstaller myFile.py). However, when I run the exe file, I get an error:
File "_plotly_utils\importers.py", line 39 in __getattr__
AttributeError: module 'plotly' has no attribute 'express'
Failed to execute script due to unhandled exception.
Here's what I tried:
- I use the
--onefileoption with pyinstaller but that did not work. - I imported plotly.express as a hidden import but I got the same error (
pyinstaller --hidden-import plotly.express myFile.py) - I copied the entire plotly package from my anaconda environment and pasted it in the same directory as
myFile.exebut I got the same error. - I updated my version of plotly with the newest version using
conda update plotly. It still didn't solve the issue. - I used the accepted solution posted here pyinstaller fails with plotly but I still got the same error.
My version of plotly is version 5.9.0.
So I ended up resolving the issue. I just created a new anaconda environment using
conda create --name <my-env>and then I reinstalled Pandas, plotly and pyinstaller. Using the commandpyinstaller myFile.pyended up creating the exe. This time, running the exe gave no error/issues. I suspect the reason for the error last time was because of some dependency/library/module conflicts which prevented the exe from recognizing plotly.