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 · 13 comments
Closed

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

jvaldiviezo9 opened this issue Mar 27, 2019 · 13 comments
Labels
Milestone

Comments

@jvaldiviezo9
Copy link

jvaldiviezo9 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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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

@jvaldiviezo9
Copy link
Author

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
Copy link
Author

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

@fzumstein
Copy link
Member

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
Copy link
Author

Some idea in how to make it work with Args?

@fzumstein
Copy link
Member

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
Copy link
Author

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
Copy link
Author

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" & " "

@fanchao1985
Copy link

Hi,

I have similar problem.
image

In RunFrozenPython, I have to specify the whole path and if the path contains space, it will fail with the same message above.

Is this issue fixed already?

Best regards,
Fanchao

@fzumstein
Copy link
Member

yes, see release notes http://docs.xlwings.org/en/stable/whatsnew.html#v0-15-6-apr-29-2019. Post your VBA code and xlwings addin version if you have issues.

@fanchao1985
Copy link

Thanks a lot, Felix. It works fine after installing bas file!

Best regards,
Fanchao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants