Before introducing the method, let's start with the Python interpreter, which, because Python is a dynamically compiled language, differs from a static language such as C + +, Java, or Kotlin, and is executed at run time by compiling the edges of a sentence code. Java, which compiles high-level languages into JVM bytecode in advance, runs directly through the JVM and machine, so it runs much faster than the dynamic compilation language when performing intensive computations.
But according to the 28 law (Pareto Law), 80% of computing resources are only used by 20% of programs, so in most cases the native CPython interpreter is enough for everyday programming, and many scientific computing libraries are written at the bottom of C + +, and are generally not used for intensive computing in Python.
However, there is a magic thing called PyPy, it uses JIT (just-in-time) technology, mixed with dynamic compilation and static compilation features, is still a sentence to compile the source code, but the translated code will be cached to reduce performance loss. In contrast to static code compilation, Just-in-time code can handle deferred binding and enhance security.
Now the official latest version is Python 3.5, and when you download and install Python from the website, you bring in a CPython interpreter, the most widely used Python interpreter, where we use Python in the terminal xxx.py The command is the CPython interpreter that is invoked.
The pypy we just mentioned is also an interpreter, using the pypy xxx.py command.
The pro-test shows that the speed of intensive computing is almost java.
Let's talk about how to install the PyPy interpreter on the Pycharm (Mac OS for example, the rest of the system to update later, the process is actually similar).
1. access to the official website (http://pypy.org/download.html), you can find that the current PYPY-compliant Python 3.5 package is still in beta, only to provide the source and Linux version of the beta package, So there is no Mac version of the stability pack, but 2.7 is already a stable version, find mac OS X binary (64bit) to download a compatible 2.7 package.
If a classmate really needs the Python 3 version of PyPy, click on all of our downloadsto find pypy3.3-v5.5.0-alpha-osx64.tar.bz2 downloads, This is the latest compatible Python 3 Mac System package that can be used directly, and 3.5 is expected to wait for some time.
2. OK, I have too much nonsense, whether you are under the pypy2-v5.8.0-osx64.tar.bz2 or pypy3.3-v5.5.0-alpha-osx64.tar.bz2, Now unzip to any directory below.
3. Open Pycharm, enter Preferences, and find Project interpreterbelow Project:python , In the Drop-down list you can see all the Python interpreters you have now.
Click Show All, then add, select AddLocal,
Find the directory you just unzipped PyPy, lock the pypy3.3 below the bin directory, and select OK. Then Pycharm will prompt you install related tools, click will automatically add the relevant tools, and finally click OK to complete the configuration.
Re-open the Python console to find that the interpreter has become pypy, if you need to switch back to the native interpreter, and then set up in the preferences, this is the pycharm convenient place.
However, it should be noted that most of the Python code can run under PyPy, but PyPy and CPython are different, which can result in the same Python code being executed under both interpreters. If your code is to be executed under PyPy, you need to know where they differ, refer to the official documentation:
http://pypy.readthedocs.org/en/latest/cpython_differences.html