How to decompile compiled .pyc python files to find/see original source code

Hello,everyone.In this post,i am sharing how to decompile compiled python files which are in .pyc formats usually.It may be useful for reverse enginering and if you want to know the original source code of any compiled python files.It may be also useful whenever  your original .py  python file is deleted unknowingly and there is only compiled .pyc file left  on disk and you want your original .py file back.In all those cases, this method can be used.

I have used Ubuntu OS here and it can be used on Windows OS also.

Tools Required :

uncompyle6  : https://github.com/rocky/python-uncompyle6/

Thanks :R. Bernstein (Author of uncompyle6)

Steps :

1.Install uncompyle6 by using pip on Terminal or you can download from above link and install it by running its setup.py file.To install uncompyle6 by using pip,use this command on Terminal :

pip install uncompyle6

 

2.After installation of  uncompyle6 ,you can check its successfull installation and its usage by running uncompyle6 command on Terminal (see screenshot).

 

3.To decompile any file in current diectory ,use command (see screenshot for example): uncompyle6 -o . <file-name.pc> 

Example : uncompyl6 -o . txfile.pyc rxfile.pyc

Screenshot from 2017-07-01 13-38-05

 

4.You will see your decompiled files created with same name in the current working directory(or desired directory) .Now,you can open this decompiled file with any Text Editor and see original source code.

Screenshot from 2017-07-01 13-38-46.png

 

5.if you want to see decompiled code on terminal(standard output),use command(see screenshot for example ): uncompyle6 <filename.pyc>

Screenshot from 2017-07-01 13-39-59.png

 

Thanks for reading my post.I hope this will be useful for python users who want to decompile compiled python files.

 

 

 

 

Using Python3 and Python2 on Windows OS with pip support

Hello everyone.Today,I am going to share how to use Python3 and Python2 with pip support  on Windows OS.If you try to install latest Python version 3.6 ,it provides you the option of adding Python 3.6 to PATH ,but this is not provided by Python2 installer still.Many users may find it difficult to use both version with corresponding pip on Windows OS.

So,I am sharing this method which helped me to use Python2 and Python3 simultaneously.

STEPS :

1.Download Python3 and Python2 installer from python.org .

2.Run Python3 installer and tick(enable) “Add Python 3.6 to Path” as shown in screenshot so that you can run Python3 by python command on Terminal/Shell.

p3s

 

3.You can run Python3 by using python command and its pip by using pip command.

4.Run Python2 installer and install Python2 .

5.Now ,you need to edit system environment  variable PATH as shown in screenshot below  for using Python2  and its pip2 in Terminal/shell :

path_setup

 

6.Click on Edit Button .After that all the enteries of  PATH  variable will be displayed.Now,click on New Button and add this entry as shown in screenshot:

C:\Python27\Scripts

path_edit.JPG

 

7.Click on OK button to save and make it sure that the entry added to PATH varaiable is not C:\Python27  . Otherwise , python command will run Python2 instead of Python3 .

8. Again add a new entery PY_PATH to system variables and set its value to 2 if you want to run python2 by using py command.

9.Now, you can use Python 3 by using python or py -3 . You can use pip for python 3 by pip or pip3 command .You can use Python2 by using py command or py-2 command .You can use pip for Python2 by using pip2 command.(See Screenshot)

pipnnn.JPG

 

If every step is followed correctly,you will see Python3 and Python2 running successfully with pip support in Terminal.

If you have any query or you need help,post in comments.I will be glad to help you.

Thanks for reading my post.I hope my post will be useful to Python users who are using Windows OS.