1. Anthony Tuininga
  2. cx_Freeze
  3. Issues
Issue #15 invalid

wrong behavior of cx_Freeze, when source-program is without ".py"-extension

Andrej Antonov
created an issue

good day! :)

i will show this in example:

step 1: making source

making source file ("test-exception-message"):

$ cat test-exception-message 
#!/usr/bin/env python3

if __name__ == '__main__':
    raise Exception('***** SOME MESSAGE *****') # we want will see this message!

it just displays error with message.

file name ("test-exception-message") MUST be without py-extension.

this works correctly with default python:

$ chmod -v +x test-exception-message 
mode of `test-exception-message' changed to 0775 (rwxrwxr-x)

$ ./test-exception-message
Traceback (most recent call last):
  File "./test-exception-message", line 4, in <module>
    raise Exception('***** SOME MESSAGE *****') # we want will see this message!
Exception: ***** SOME MESSAGE *****

step 2: using cx_Freeze

$ cxfreeze -s test-exception-message
$ ls
dist  test-exception-message

step 3: removing (or renaming) source file

this step is also important.

$ mv -v test-exception-message __REMOVED__test-exception-message__
`test-exception-message' -> `__REMOVED__test-exception-message__'

step 4: running dist-version

$ dist/test-exception-message 
Traceback (most recent call last):
  File "/home/regular-user/.local/lib/python3.2/site-packages/cx_Freeze/initscripts/Console3.py", line 27, in <module>
    exec(code, m.__dict__)
  File "test-exception-message", line 4, in <module>

message of exception not shown.

program has crashed earlier, then show error message.


thanks in advance!

sorry for bad english.

Comments (16)

  1. Andrej Antonov reporter

    i detected, that -- we get this issue -- when BINARY file name has same name as was SOURCE file .

    for example if we renaming result binary file -- it will be correct working:

    $ ls
    dist  __REMOVED__test-exception-message__
    
    $ dist/test-exception-message 
    Traceback (most recent call last):
      File "/home/regular-user/.local/lib/python3.2/site-packages/cx_Freeze/initscripts/Console3.py", line 27, in <module>
        exec(code, m.__dict__)
      File "test-exception-message", line 4, in <module>
    
    $ mv -v dist/test-exception-message dist/____test-exception-message___
    `dist/test-exception-message' -> `dist/____test-exception-message___'
    
    $ dist/____test-exception-message___
    Traceback (most recent call last):
      File "/home/regular-user/.local/lib/python3.2/site-packages/cx_Freeze/initscripts/Console3.py", line 27, in <module>
        exec(code, m.__dict__)
      File "test-exception-message", line 4, in <module>
    Exception: ***** SOME MESSAGE *****
    
  2. Thomas Kluyver

    Good catch - I guess most programs don't see it, because the script is often just a thin wrapper around modules containing the actual code.

    The linecache module is responsible for finding lines for tracebacks. If the structure of the cache has been consistent over the Python versions we support, we could manually insert the code under the name of the script.

  3. Andrej Antonov reporter

    Thomas Kluyver > I guess most programs don't see it, because the script is often just a thin wrapper around modules containing the actual code.

    yes! too unusual conditions for the emergence of this issue (#15) :-)

    Thomas Kluyver > The linecache module is responsible for finding lines for tracebacks. ...

    but, may i change (where it variable in cx_Freeze?) string-variable that need for storing filename of programm-source ("test-exception-message") ?

  4. Andrej Antonov reporter

    at best, I would make the fix, which would allow NOT to store filenames of program-source-code, when we makes binaries.

    (of course -- as addition option)

    however, an annoying problem is that -- i have not yet understand how to do it :-)

  5. Thomas Kluyver

    Ah, no, it's more complicated than I thought. We don't actually have the source code of the file, because it's stored in the zip file as a .pyc file, at least by default. So no, I don't think we can resolve that.

    I'm a bit mystified, though, because we store all Python code as .pyc files, and I'm sure I've had meaningful tracebacks from systems which only had the frozen copy available.

  6. Andrej Antonov reporter

    as I understand it --./dist/test-exception-message[.zip]/__main__.pyc -- it is compiled of ./test-exception-message .

    and information about source file name ("test-exception-message") storied in this dist/test-exception-message[.zip]/__main__.pyc ?

    If so, I think too -- we can not really fix the issue. [at least clean way :), without hacks such: temporary copy main-source-file, then compile, then delete main-source-file (too dirty hack. or not?)]

  7. Andrej Antonov reporter

    i think:

    ...hack "copy-to-tmp-file , compile , delete-tmp-file" -- it is bad solution.

    ...show warning message if cx_Freeze detected that main-source-file is without .py (or .pyw) extension -- is better solution. :-)

    what do you think?

  8. Thomas Kluyver

    I don't see how a tmp file during compilation would help - it's looking for the source lines when the error occurs at runtime. And I'm not sure that the .py extension is relevant. But I'm starting to get the feeling that I'm missing something here...

  9. Andrej Antonov reporter

    it's looking for the source lines when the error occurs at runtime

    this whole problem is that the source-file-names are stored at compile-time, not runtime.. :-(

    I NOT found a fragment-of-code inside of cx_Freeze who stores source-file-names. but I found by experiment-way -- that the names of the source files are stored in binary (inside .pyc?).

    and if we make a compilation from other directory (not from project directory) -- even directory-path stored at compile-time.

    we will try to make next experiment:

    $ ls
    test-exception-message
    
    
    $ cat test-exception-message
    #!/usr/bin/env python3
    
    if __name__ == '__main__':
        raise Exception('***** SOME MESSAGE *****') # we want will see this message!
    
    
    $ mkdir STRANGE_DIRECTORY_NAME
    
    
    $ cp -v test-exception-message STRANGE_DIRECTORY_NAME/
    `test-exception-message' -> `STRANGE_DIRECTORY_NAME/test-exception-message'
    
    
    $ cxfreeze -s STRANGE_DIRECTORY_NAME/test-exception-message
    
    $ unzip dist/test-exception-message
    ... ... ...
    ... ... ...
    ... ... ...
    
    
    $ chmod +r __main__.pyc
    $ xxd __main__.pyc 
    0000000: 6c0c 0d0a e5a3 e550 6300 0000 0000 0000  l......Pc.......
    0000010: 0000 0000 0002 0000 0040 0000 0073 1f00  .........@...s..
    0000020: 0000 6500 0064 0000 6b02 0072 1b00 6501  ..e..d..k..r..e.
    0000030: 0064 0100 8301 0082 0100 6e00 0064 0200  .d........n..d..
    0000040: 5328 0300 0000 7508 0000 005f 5f6d 6169  S(....u....__mai
    0000050: 6e5f 5f75 1800 0000 2a2a 2a2a 2a20 534f  n__u....***** SO
    0000060: 4d45 204d 4553 5341 4745 202a 2a2a 2a2a  ME MESSAGE *****
    0000070: 4e28 0200 0000 7508 0000 005f 5f6e 616d  N(....u....__nam
    0000080: 655f 5f75 0900 0000 4578 6365 7074 696f  e__u....Exceptio
    0000090: 6e28 0000 0000 2800 0000 0028 0000 0000  n(....(....(....
    00000a0: 752d 0000 0053 5452 414e 4745 5f44 4952  u-...STRANGE_DIR
    00000b0: 4543 544f 5259 5f4e 414d 452f 7465 7374  ECTORY_NAME/test
    00000c0: 2d65 7863 6570 7469 6f6e 2d6d 6573 7361  -exception-messa
    00000d0: 6765 7508 0000 003c 6d6f 6475 6c65 3e03  geu....<module>.
    00000e0: 0000 0073 0200 0000 0c01                 ...s......
    

    this experiment showed that word STRANGE_DIRECTORY_NAME/test-exception-message present in __main__.pyc

  10. Thomas Kluyver

    Ah, in fact I think it might be a bug in Python itself - when it can find the filename associated with the code, but can't load lines of code, it fails to display the exception message:

    $ touch bar
    $ python3
    Python 3.2.3 (default, Oct 19 2012, 19:53:57) 
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> exec(compile("raise Exception('blather')", "foo", "exec"))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "foo", line 1, in <module>
    Exception: blather
    >>> exec(compile("raise Exception('blather')", "bar", "exec"))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "bar", line 1, in <module>
    
    >>> 
    

    My testing suggests that this is fixed in Python 3.3, though.

  11. Andrej Antonov reporter

    yes. i compiled Python-3.3 [before that I used default Python3.2 from Fedora-16]

    in Python-3.3 --

    $ touch bar && python3.3 -c 'exec(compile("raise Exception(\"blather\")", "bar", "exec"))'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "bar", line 1, in <module>
    Exception: blather
    

    -- works good!

    and i just compiled cx_Freeze for Python-3.3 . this issue (#15) not affect it! :)

    I'm sorry that spent your time! [i think issue(#15) may be closed]

  12. Log in to comment