Skip to content

UDF Import - Cannot Find File - Issue with Show Console False #1421

@patmann03

Description

@patmann03

OS (e.g. Windows 10 or macOS Sierra)

Windows 10

Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)

20.7, Excel 365 Build 1908, Python 3.8.5

Describe your issue (incl. Traceback!)

The VBA code tries to load the pythonw.exe when show Console is set to False, but screws up the file path by replacing python with pythonw.

This results in a dll error that the file could not be found because the pythonw path (described below) does not exist. Checking 'Show Console" to true fixes this.

Here in the VBA Code:

    PYTHON_WIN = GetConfig("INTERPRETER_WIN", "")
    If PYTHON_WIN = "" Then
        ' Legacy
        PYTHON_WIN = GetConfig("INTERPRETER", "pythonw")
    End If
    DEBUG_UDFS = GetConfig("DEBUG UDFS", False)

    ' Show Console requires python if True otherwise pythonw
    If GetConfig("SHOW CONSOLE", False) = True Then
        If InStr(1, PYTHON_WIN, "pythonw") > 0 Then
            PYTHON_WIN = Replace(PYTHON_WIN, "pythonw", "python")
        End If
    Else
        If InStr(1, PYTHON_WIN, "pythonw") = 0 Then
            PYTHON_WIN = Replace(PYTHON_WIN, "python", "pythonw")
        End If
    End If

It pulls in the interpreter, it then replaces python in the file path with pythonw. This results in an invalid filepath:

c:\users\<user>\appdata\local\programs\pythonw\pythonw38\pythonw.exe

instead of:
c:\users\<user>\appdata\local\programs\python\python38\pythonw.exe

If I replace the line here:

PYTHON_WIN = Replace(PYTHON_WIN, "python", "pythonw")

to

PYTHON_WIN = Replace(PYTHON_WIN, "python.exe", "pythonw.exe")

I can import UDFs without having to have the 'Show Console' set to True

# Your traceback here

Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)

# Your code here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions