问题
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