Pyinstaller with Plotly, Orca and Psutils not working

I created a python scritp that uses the principle of the’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

             datas=[('C:/My/Path/to/Python/Python37/Lib/site-packages/plotly/', './plotly/'),
                    ('C:/My/Path/to/Python/Python37/Lib/site-packages/psutil/', './psutil/'),
                    ('C:/My/Path/to/orca/', './orca/')],
             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.

Hi @ShooterBoyX,

I’m not very familiar with PyInstaller, but here are some general things to look at.

By default, 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:

import os

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/'])

(Note: '/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 exactly where to find orca with:

import as pio
pio.orca.config.executable = '/path/to/pyinstalled/orca/orca.exe'

See for more information.

Hope that helps!

Thank you for your quick reply @jmmease !

Since I also would like to run the script using python, 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
import sys
import os 
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)
elif __file__:
    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.

1 Like

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?

Hello @jmmease,

Good day!

I created a python script that uses the principle of the’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.