Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space in frozen python (name.exe) path causes error #1063

Closed
jvaldiviezo9 opened this issue Mar 27, 2019 · 10 comments

Comments

Projects
None yet
2 participants
@jvaldiviezo9
Copy link

commented Mar 27, 2019

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)

Latest xlwings v15.5

Describe your issue (incl. Traceback!)

Capture

# Your traceback here


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

# Your code here

On vba after generating the dist executable with pyinstaller I've got this:

Sub run_frozen()
    
    this_path = ThisWorkbook.Path
    'this_path = "D:\Desktop\project test\"    - note the space on project test folder
    RunFrozenPython (this_path + "\dist\" + "pyfile.exe")

End Sub

on python I've got a simple file that writes to a cell on excel

import xlwings as xw
wb = xw.Book.caller()
wb.sheets("Sheet1").range("A1") = "ok

the problem arises when on the path I've one space, let's call it:
this_path_fails = "D:\Desktop\project test\"
this doesn't happen when we put an underscore in the path or remove the space.
this_path_works = "D:\Desktop\project_test\"


@fzumstein fzumstein added this to the 0.15.6 milestone Mar 27, 2019

@fzumstein fzumstein added the bug label Mar 27, 2019

@fzumstein

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

Can't seem to make this work. I would have the following changes expected to work (wrapping the whole string and the path in "):

in Main:

    ExitCode = Wsh.Run("cmd.exe /C " & Chr(34) & DriveCommand & _
                   RunCommand & _
                   "--wb=" & """" & WORKBOOK_FULLNAME & """ --from_xl=1" & " --app=" & Chr(34) & _
                   Application.Path & "\" & Application.Name & Chr(34) & " --hwnd=" & Chr(34) & Application.Hwnd & Chr(34) & _
                   Chr(34) & " 2> """ & LOG_FILE & """ ", _
                   WindowStyle, WaitOnReturn)

Then call RunFronzePython like this:

Sub SampleCall()
    RunFrozenPython Chr(34) & ThisWorkbook.Path & "\dist\frozenargs\frozenargs.exe" & Chr(34) & " arg1 arg2"
End Sub

@fzumstein fzumstein removed this from the 0.15.6 milestone Apr 28, 2019

@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

did you try to just put the quotation on the part of the path that contains spaces?
In what file is this code located on source code?

@fzumstein

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

should have tried that too, yes. Double click the xlwings addin (password xlwings), then this is in Main module

@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

Found solution!
The issue is on PythonCommand, we need to put the double quotes there instead WORKBOOK_FULLNAME.
I added this to the RunCommand and it worked
image

@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

ElseIf IsFrozen = True Then
    RunCommand = PythonCommand
    'Debug.Print RunCommand
    RunCommand = Chr(34) & RunCommand & Chr(34) & " "
    'Debug.Print RunCommand
End If
@fzumstein

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

the issue is that it doesn't work with arguments. In your case, you should be able to resolve it by leaving the xlwings addin untouched and changing your call to this:

Sub run_frozen()
    
    this_path = ThisWorkbook.Path
    RunFrozenPython (Chr(34) & this_path + "\dist\" + "pyfile.exe" & Chr(34))
@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

Some idea in how to make it work with Args?

@fzumstein

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

Ah ok I see what's going on, you're right, currently you have to hack it there. Yes, I'll probably have to separate out the args to make this work. Thanks for your help!

@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

You're welcome :). So is this still planned for the next release?

@fzumstein fzumstein added this to the 0.15.6 milestone Apr 28, 2019

@jvaldiviezo9

This comment has been minimized.

Copy link
Author

commented Apr 28, 2019

If this helps I figured out that this mod works with args:
RunCommand = Chr(34) & "D:\Desktop\path with spaces\dist\test_args.exe" & Chr(34) & " " & "Arg1 Arg2" & " "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.