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:
--onefile
option with pyinstaller but that did not work.pyinstaller --hidden-import plotly.express myFile.py
)myFile.exe
but I got the same error.conda update plotly
. It still didn't solve the issue.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 command pyinstaller myFile.py
ended 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.