1

Context is that my Python 3.9 source code files were deleted.

Earlier, I forgot to add .gitignore in my repository root of my Python Django Project and I committed the code to my github repository. Now the root folder contains __pycache__, where all the compiled python files are located. I tried looking at, how to decompile the files and found the required resource uncompyle6 on PyPI. However, it works for Python 2.4 - 3.8. In addition, there is a Python decompiler decompyle3 for Python 3.7 - 3.8 which is stripped down from uncompyle6. But the version of Python I have been using all along is Python 3.9. Is there a way I can get around this and be able to solve my problem of decompiling my .py files anyhow so I can get the earlier project structure that I require?

Edit: unpyclib and Decompyle++ are another tools that I looked into, however both are Python 2.xx only programs. The most successful decompiler is uncompyle6(offering support upto Python 3.8 as of now) as is quite evident from several other responses on stackoverflow.

RichVel
  • 7,030
  • 6
  • 32
  • 48
mostlycryptic
  • 197
  • 1
  • 6
  • 20
  • Have you tried to install them and run it? Are you getting error? – TYZ May 01 '21 at 19:41
  • 1
    If you still have the source files, why do you need to decompile from `__pychache__`. I think I'm missing something here. – joanis May 01 '21 at 20:00
  • @joanis I actually don't. I dont have the source files. If I did, there was no point in trying to decompile `__pycache__`. I'd delete the code from the repository and commit the code all over again, which would be more convenient. – mostlycryptic May 01 '21 at 20:03
  • 2
    OK, sorry, that's what I misunderstood. This question makes more sense now. I would suggest editing the question to explicitly state that you no longer have the source code. – joanis May 01 '21 at 20:04
  • @TYZ Yes I did and decompyle3 throws the error: decompyle3 requires Python 3.7-3.8 – mostlycryptic May 01 '21 at 20:05
  • According to https://stackoverflow.com/a/66989736/3216427 you might still be out of luck. – joanis May 01 '21 at 20:08
  • @joanis Thanks! I did see that! I was still optimistic and thought someone might come to my rescue! Fingers crossed as yet! I tried decompyle++ as well, but it doesn't seem to work as well. – mostlycryptic May 01 '21 at 20:13
  • How about creating a virtualenv with python3.8 and install it? – TYZ May 01 '21 at 21:07
  • @TYZ I created pipenv and installed python 3.8 in it. However, when trying to decompile using uncompyle6, it throws errors probably due to the bytecode being python3.9 compatible. I'll share the partial traceback in the follow-up comment. – mostlycryptic May 02 '21 at 08:22
  • Partial traceback is here: ```Traceback (most recent call last): File "C:\Users\Hp\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 192, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\Hp\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Hp\.virtualenvs\django_project-xqJgaO6Z\Scripts\uncompyle6.exe\__main__.py", line 7, in ``` – mostlycryptic May 02 '21 at 08:24
  • There doesn't appear to be any tool supporting Python 3.9+ decompilation - see latest updates to [this answer](https://stackoverflow.com/a/14808336/992887) – RichVel Apr 01 '23 at 08:34

0 Answers0