Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of pypy compiler

Is there a difference in python programming while using just python and while using pypy compiler? I wanted to try using pypy so that my program execution time becomes faster. Does all the syntax that work in python works in pypy too? If there is no difference, can you tell me how can i install pypy on debian lunux and some usage examples on pypy? Google does not contain much info on pypy other than its description.

like image 998
Justin Carrey Avatar asked Sep 14 '12 20:09

Justin Carrey


People also ask

Why PyPy is faster than Python?

PyPy is implemented in Python, but it implements a JIT compiler to generate native code on the fly. The reason to implement PyPy on top of Python is probably that it is simply a very productive language, especially since the JIT compiler makes the host language's performance somewhat irrelevant.

How do I run a program with PyPy?

For Python 2.7, it's just called pypy . For CPython, if you would like to run Python 3 from the terminal, you simply enter the command python3 . To run PyPy, simply issue the command pypy3 .

What does PyPy stand for?

PyPy means "Python in Python". It is an alternative implementation of the Python language. Usually, when we speak of "Python", we can mean two different things. On the one hand it means "Python as an abstract programming language".

Is PyPy same syntax as Python?

PyPy is an implementation of the Python programming language written in Python. The Interpreter is written in RPython (a subset of Python). PyPy uses Just In Time (JIT) compilation. In simple terms, JIT uses compilation methods to make the interpreter system more efficient and fast.


2 Answers

From the pypy features page:

PyPy 1.9 implements Python 2.7.2 and runs on Intel x86 (IA-32) and x86_64 platforms, with ARM and PPC being underway. It supports all of the core language, passing the Python test suite.

This means that pretty much any code that you've written in Python 2.7 will work. The only exceptions worth mentioning are some python extensions written in C, such as numpy.

Installation should be fairly easy, you can download a linux binary from here. Then simply extract the interpreter. From this point, you can run your python programs similar to how you would run them with the normal python interpreter.

At the command line, instead of:

python my_program.py

Use:

path/to/where/you/installed/pypy my_program.py

For examples of how/why you might want to use pypy, check out this video from PyCon 2012.

like image 134
Wilduck Avatar answered Sep 22 '22 18:09

Wilduck


pypy is a compliant alternative implementation of the python language. This means that there are few (intentional) differences. One of the few differences is pypy does not use reference counting. This means, for instance, you have to manually close your files, they will not be automatically closed when your file variable goes out of scope as in CPython.

like image 45
Hans Then Avatar answered Sep 23 '22 18:09

Hans Then