dexplo / dataframe_image

A python package for embedding pandas DataFrames as images into pdf and markdown documents
https://dexplo.org/dataframe_image
MIT License
282 stars 41 forks source link

in Windows 11: Failed with FileNotFoundError: [WinError 2] The system cannot find the file specified #111

Closed bigheadming closed 1 month ago

bigheadming commented 9 months ago

OS: Windows 11 Home OS Version: 23H2 Python: 3.9.18 Chrome installed: No Brave installed: Yes

Description:

Code:

import dataframe_image as dfi

xxx = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]})
xxx_styled = xxx.style.background_gradient().format(precision=3)
xxx_styled

# Failed with error: FileNotFoundError: [WinError 2] The system cannot find the file specified
dfi.export(xxx_styled, 'c:\\Temp\\xxx.png') 

# Succeeded
dfi.export(xxx_styled, 'c:\\Temp\\xxx2.png', table_conversion='matplotlib') 

# Succeeded after hacking into dataframe_image\converter\browser\chrome_converter.py 
# and the changed the followings:
# locs = [
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\brave.exe",
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe",
# ]
dfi.export(xxx_styled, 'c:\\Temp\\xxx3.png')
PaleNeutron commented 1 month ago

Is your windows 32bit or 64bit?

bigheadming commented 1 month ago

Edition: Windows 11 Home System Type: 64-bit operating system, x64-based processor

PaleNeutron commented 1 month ago

Strange...

Refer to https://learn.microsoft.com/en-us/windows/win32/winprog64/registry-redirector

Redirected keys are mapped to physical locations under Wow6432Node. For example, HKEY_LOCAL_MACHINE\Software is redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node. However, the physical location of redirected keys should be considered reserved by the system. Applications should not access a key's physical location directly, because this location may change. For more information, see Accessing an Alternate Registry View.

SOFTWARE\Microsoft should be a alias of SOFTWARE\WOW6432Node\Microsoft.

PaleNeutron commented 1 month ago

I think the most likely problem is the order of three browsers. Please check if Chrome or Firefox's registry key exist but no binary located at the key's value.

bigheadming commented 1 month ago

This bug was reported a while ago. Over the time, I uninstalled Chrome but I still have Firefox and Brave. I can find both brave.exe and frefox.exe in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ in the registry. In both the value of (Default) key is C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe and C:\Program Files\Mozilla Firefox\firefox.exe respectively. I verified that both exe files exist in their paths.

Brave is my primary browser. You mentioned that it may be "the order of three browsers". What's needed to do without hacking into chrome_converter.py?

Hope this is what you asked. Thanks.

PaleNeutron commented 1 month ago

I realize that you change the order of three browsers in your solution. So I think it may not a problem with WOW6432Node path in registry but system find chrome.exe path first but it does not work.

# Succeeded after hacking into dataframe_image\converter\browser\chrome_converter.py 
# and the changed the followings:
# locs = [
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\brave.exe",
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
#     r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe",
#     # r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe",
# ]

If the problem is the order. There are two solutions:

  1. Uninstall chrome and edge from your computer and make sure the registry is cleaned.
  2. use chrome_path parameter. like this: dfi.export(xxx_styled, 'c:\\Temp\\xxx.png') , chrome_path="your/path/of/brave.exe"
bigheadming commented 1 month ago

Since I don't have Chrome installed, I can't uninstall it. Here are what I've tried:

  1. Uninstall dataframe_image and reinstall it (to 0.2.5):

dfi.export(xxx_styled, 'c:\Temp\xxx.png') failed with the following error:

File c:\Users\xxx\miniconda3\envs\py311_ml\Lib\site-packages\dataframe_image\converter\browser\chrome_converter.py:70, in get_chrome_path(chrome_path) 64 locs = [ 65 r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", 66 r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe", 67 r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe", 68 ] 69 for loc in locs: ---> 70 handle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, loc) 71 num_values = winreg.QueryInfoKey(handle)[1] 72 if num_values > 0:

FileNotFoundError: [WinError 2] The system cannot find the file specified

  1. Same as before with chrome_path specified:

dfi.export(xxx_styled, 'c:\Temp\xxx.png', chrome_path="C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" ) was run successfully.

  1. Use another Windows 11 64bit machine with Chrome installed

    dfi.export(xxx_styled, 'c:\Temp\xxx.png') was run successfully.

So, it seems that one needs to specify chrome_path if Chrome is not installed, even if a Chrome-based browser like msedge.exe and brave.exe is available and is shown in the locs list in package code "chrome_converter.py:70":

locs = [ r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe", r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe", ]

Is it supposed that chrome_converter.py would use the next one in the locs if the current one can't be found? I am trying to see if one can avoid specifying chrome_path.

Overall, it works now with update to 0.2.5 and specfy chrome_path if the windows machine don't have chrome installed.

PaleNeutron commented 1 month ago

Can you install latest source from github and test does it works without specific chrome path?

bigheadming commented 1 month ago

Using the source from github, It works now even without specifying chrome_path and without having chrome.exe installed. (In my case, I have brave.exe installed in my machine.)

dfi.export(xxx_styled, 'c:\Temp\xxx.png')

Thank you for the fix!