1

I'm trying to use pyinstaller (latest version) to package D-table as an EXE file, but I'm getting this error:

FileNotFoundError: No such file of directory: ...\dash_colorscales\metadata.json.**
FileNotFoundError: No such file of directory: ...\dtale\translations.

I have tried to use a hook file as below, but still it didn't work.

from PyInstaller.utils.hooks import collect_data_files, collect_submodules
hiddenimports = collect_submodules('dtale')
datas = collect_data_files('dtale', include_py_files=True)

How can I fix this?

Here is my main.py file:

import dtale

if name == 'main':
    dtale.show().open_browser()
    app = dtale.app.build_app(reaper_on=False)
    app.run(host="0.0.0.0", port=8080)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Milleon
  • 35
  • 6

1 Answers1

1

You need to add all of the json and js files from the dash_daq and dash_colorscales as data with the compiled contents.

These are the steps I took to compile and run the application.

  1. Open a new directory and cd into it.

  2. Create a clean virtual env with python -m venv venv and activate it with venv\scripts\activate

  3. Install dependencies with pip install dtale pyinstaller

  4. I copied the example code from the dtale GitHub page into a main.py file

    main.py

    import dtale
    import pandas as pd
    df = pd.DataFrame([dict(a=1,b=2,c=3)])
    d = dtale.show(df, subprocess=False)
    tmp = d.data.copy()
    tmp['d'] = 4
    d.kill()
    d.open_browser()
    dtale.instances()
    
  5. Run pyinstaller -F --collect-all dtale main.py

  6. Inside of the created .spec file, add the following lines at the top.

    # -*- mode: python ; coding: utf-8 -*-
    from PyInstaller.utils.hooks import collect_all
    import os
    
    dash_daq = "./venv/Lib/site-packages/dash_daq/"
    datas = [
        ('./venv/Lib/site-packages/dash_colorscales/metadata.json', './dash_colorscales/'),
        ('./venv/Lib/site-packages/dash_colorscales/bundle.js', './dash_colorscales/')]
    for filename in os.listdir(dash_daq):
        if os.path.splitext(filename)[1] in [".js", ".json"]:
            filepath = os.path.join(dash_daq, filename)
            datas.append((filepath, "./dash_daq/"))
    
    binaries = []
    hiddenimports = []
    tmp_ret = collect_all('dtale')
    datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
    
    block_cipher = None
    
  7. Run pyinstaller main.spec

  8. Run dist/main.exe

And Bob’s your uncle.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexander
  • 16,091
  • 5
  • 13
  • 29
  • FileNotFoundError: [WinError 3] The system cannot find the path specified: '...\\dtale\\translations' This was the error I am still getting. – Milleon Mar 26 '23 at 08:57
  • Thanks Alexander! I think I'm much closer but still getting this error: 9882 WARNING: Unable to find package for requirement six from package dtale. 9882 WARNING: Unable to find package for requirement cycler from package dtale. 9882 WARNING: Unable to find package for requirement beautifulsoup4 from package dtale. 9882 WARNING: Unable to find package for requirement scikit-learn from package dtale. But I am able to see these modules in my site-packages folder.. And for the Step 6, I should be pasting that whole section above the codes for a, pyz and exe? – Milleon Mar 26 '23 at 09:14
  • @Milleon Then you did something wrong or didn't follow the steps in my example exactly – Alexander Mar 26 '23 at 11:11
  • I followed it exactly. Can you clarify Step 6? Maybe this was where I made a mistake. Do I replace the whole .SPEC file or which lines do I specifically add/where? – Milleon Mar 26 '23 at 11:18
  • @Milleon No you leave your spec file exactly the way it is, but add all the lines in step 6 at the top. except for maybe the last one, since it would probably be duplicate. In other words, copy everything except `block_cipher = None` at the top of your .spec file – Alexander Mar 26 '23 at 11:25
  • I am using this as my main.py, as I want it to run on a localhost continuously: ` import dtale if __name__ == '__main__': dtale.show().open_browser() app = dtale.app.build_app(reaper_on=False) app.run(host="0.0.0.0", port=8080) ` – Milleon Mar 26 '23 at 16:18
  • 11720 WARNING: Unable to find package for requirement cycler from package dtale. 11720 WARNING: Unable to find package for requirement six from package dtale. 11720 WARNING: Unable to find package for requirement beautifulsoup4 from package dtale. 11720 WARNING: Unable to find package for requirement scikit-learn from package dtale. 11728 WARNING: Unable to find package for requirement flask-ngrok from package dtale. Also, I see these modules in the site-packages folder but when I run the .SPEC file it says otherwise. – Milleon Mar 26 '23 at 16:23
  • then you didn't activate your virtual enviornment... Sorry that might be my bad actually, I assumed you knew what a virtual environment was... take another look at instruction number 2... I edited it to add the command to activate the virtual env – Alexander Mar 26 '23 at 19:33
  • I did actually. I just retried it again from scratch, and I'm getting this error when running step 4.. Can you you try with my main.py content in the comment above? Thanks. ** OSError: [WinError 4393] The tag present in the reparse point buffer is invalid: '...\\venv\\lib\\site-packages\\plotly\\validators\\layout\\template' ** – Milleon Mar 26 '23 at 20:44
  • @Milleon Edit your question and include the contents of your main.py at the end of your question – Alexander Mar 26 '23 at 20:52
  • If you have a working .exe using my main.py contents, could you share it with me through a link to download? – Milleon Mar 26 '23 at 20:55
  • Ok added my main.py in the question. Thanks! – Milleon Mar 26 '23 at 20:57
  • okay. give me a couple minutes. – Alexander Mar 26 '23 at 21:49
  • DId you try using the script in my example? – Alexander Mar 26 '23 at 21:57
  • Here is a literal screen recording from start to finish... https://file.io/jW01H1YeBwSn – Alexander Mar 26 '23 at 22:27
  • 1
    Thank you so much for going all the way to help me out, really appreciate what you did. Would upvote you x100 if that is possible. Even though it is working now for me, I honestly don't know what was the reason why it wasn't working before. The steps look identical, except that I was doing all steps 5 & 7 in CMD while following your video I did it in VS Code.. – Milleon Mar 27 '23 at 03:41