I created a python scritp that uses the principle of the plot.ly’s static image export using orca and psutil. The script works with orca and psutil. Now my goal is to create a standalone exectuable using Pyinstaller. Note that:
I installed orca using the standalone binaries and their installer. See the third method of their README-file
The pyinstaller creates a dist folder in which an executable can be ran, using some packages (such as plotly in this example) to supply the .exe file with its needed resources
I have ran a test without static image export, which worked!
Now, when trying this with orca and psutil I ran into a couple of problems. I edited my .spec file so that
hiddenimports=['plotly', 'orca', 'psutil']
This did move the folders I expected it to move to the dist/main folder, the problem is that it still can’t seem to use orca properly since it gives the standard traceback error where it tells you to install orca.
I’m not very familiar with PyInstaller, but here are some general things to look at.
By default, plotly.py is looking for an executable name
orca on the system
PATH. The error message you mentioned above should have printed out the current directories in the
PATH, but if not you can examine these paths by looking at the output of:
Can you confirm that this list of paths does not include the directory where you placed the orca executable?
One option is to manually add your orca directory to this path at program startup.
os.environ['PATH'] = os.pathsep.join([os.environ['PATH'], '/path/to/pyinstalled/orca/'])
'/path/to/pyinstalled/orca_dir/' should be the directory containing the
orca.exe file, and you might need to flip the slash direction on windows)
Another option is the tell plotly.py exactly where to find orca with:
import plotly.io as pio
pio.orca.config.executable = '/path/to/pyinstalled/orca/orca.exe'
See https://plot.ly/python/orca-management/#configuring-the-executable for more information.
Hope that helps!
Thank you for your quick reply @jmmease !
Since I also would like to run the script using
python main.py, the secondary option editing the
pio.orca.config.executable wasn’t a good option.
Therefore I decided to stick with adding the orca directory to the path variable at the program setup, which worked!
For that, I used the relative path of the executable created by python as described here, which made the final code look like this
# Relative path location of orca for usage with pyinstaller
orca_folder = 'orca'
# Determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
application_path = os.path.dirname(__file__)
orca_path = os.path.join(application_path, orca_folder)
os.environ['PATH'] = os.pathsep.join([os.environ['PATH'], orca_path])
Using this code and pyinstaller with the above given edited .spec file the build worked when testing on other devices without python or orca installed.
Good day! I have the same problem as you had, but your solution doesn’t help me … Maybe I didn’t correct the file .spec correctly… Could you tell me how you started pyinstaller from the command stock?
I created a python script that uses the principle of the plot.ly’s static image export using orca. The script works with orca . Now my goal is to create a standalone exectuable using Pyinstaller.
After creating, when I execute the .exe file. I am getting following error
"No module named ‘plotly.validators.table’
Note: I have added the orca directory to the path using following method
os.environ[‘PATH’] = os.pathsep.join([os.environ[‘PATH’], ‘/path/to/pyinstalled/orca/’]
It would be very grateful if you could help me to solve this issue.