Run pdb from the command line in an application packaged as a zip file?

Python can run code inside a zip archive. This explains why some code starts with a friend #!/usr/bin/env python, immediately followed by bytes of the raw zip file. See http://sayspy.blogspot.com/2010/03/various-ways-of-distributing-python.html

Python also allows users to run the python debugger conveniently for almost any code from the command line using the -m pdb option. But running this program with a zipper (for example, the popular youtube-dl program ) leads to an encoding error as follows:

$ python -m pdb /usr/bin/youtube-dl -h 
Traceback (most recent call last): 
  File "/usr/lib/python2.7/pdb.py", line 1314, in main 
    pdb._runscript(mainpyfile) 
  File "/usr/lib/python2.7/pdb.py", line 1233, in _runscript 
    self.run(statement) 
  File "/usr/lib/python2.7/bdb.py", line 387, in run 
    exec cmd in globals, locals 
  File "<string>", line 1, in <module> 
File "/usr/bin/youtube-dl", line 2
SyntaxError: Non-ASCII character '\xdb' in file /usr/bin/youtube-dl on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details 
Uncaught exception. Entering post mortem debugging 
Running 'cont' or 'step' will restart the program 
> <string>(1)<module>() 
(Pdb) 

the PEP 263 link does not talk about zip, and I'm not sure where this zip function is officially described or implemented.

, : zip , pdb __main__.py zip? , pdb ?

+4
1

PEP 273 - Zip - , .

Zip-

python -c 'import pdb, youtube_dl; print youtube_dl; pdb.runcall(youtube_dl.main, ["-h"])' youtube-dl
+1

Source: https://habr.com/ru/post/1536293/


All Articles