Using PyPy to run a Python program?

落爺英雄遲暮 提交于 2020-07-04 11:34:36

问题


I have been told that you can use PyPy to run Python programs, which is a lot faster as it is compiled using a JIT compiler rather than interpreted.

The following program finds the largest prime factor of the number 600851475143:

import numpy as np

nr = 600851475143
n = 2

while n <= np.sqrt(nr):
    if nr%n == 0:
        nr = nr/n
    n += 1
print(nr)

What would be the procedure to run this using PyPy?

I know there is documentation on their site, but I do not understand it and would appreciate a demonstration.


回答1:


Add this shebang line to the top of the program:

#!/usr/bin/env pypy

If you want to do this manually, just enter pypy main.py on the command-line.




回答2:


Keep your environment activated and go into pypyXXXX folder. Then go into bin directory and run the following commands.

pip install <packagename>

Then run your file using pypy

pypy filename.py


来源:https://stackoverflow.com/questions/25947628/using-pypy-to-run-a-python-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!