pypy

Use Sympy with Pypy

雨燕双飞 提交于 2019-12-10 15:44:30
问题 I have installed Python 2.7 and 3.5 on a Mac running with El Capitan. Moreover, I use the package Sympy (installed with pip) with python. I wanted to run my code with Pypy (installed with homebrew) but it seems that Pypy doesn't find Sympy and says: "No module named sympy" I am not an expert at all and don't know what to do now. Sympy works well with python 2 and 3 but not with Pypy. I appreciate every answer, thank you in advance. 回答1: PyPy packages are separate from Python packages. You can

Is there a way to avoid this memory error?

假装没事ソ 提交于 2019-12-10 02:58:01
问题 I'm currently working through the problems on Project Euler, and so far I've come up with this code for a problem. from itertools import combinations import time def findanums(n): l = [] for i in range(1, n + 1): s = [] for j in range(1, i): if i % j == 0: s.append(j) if sum(s) > i: l.append(i) return l start = time.time() #start time limit = 28123 anums = findanums(limit + 1) #abundant numbers (1..limit) print "done finding abundants", time.time() - start pairs = combinations(anums, 2) print

如何检查字符串是否为数字(浮点数)?

纵饮孤独 提交于 2019-12-09 16:39:34
检查字符串是否可以在Python中表示为数字的最佳方法是什么? 我目前拥有的功能是: def is_number(s): try: float(s) return True except ValueError: return False 不仅丑陋且缓慢,而且看起来笨拙。 但是我还没有找到更好的方法,因为在main函数中调用 float 更加糟糕。 #1楼 这个怎么样: '3.14'.replace('.','',1).isdigit() 仅当存在一个或不存在“。”时,它才返回true。 在数字字符串中。 '3.14.5'.replace('.','',1).isdigit() 将返回假 编辑:刚刚看到另一条评论...可以为其他情况添加 .replace(badstuff,'',maxnum_badstuff) 。 如果您传递盐而不是任意调味品(ref: xkcd#974 ),这将很好:P #2楼 这是我执行此操作的简单方法。 假设我正在遍历一些字符串,并且如果它们最终是数字,我想将它们添加到数组中。 try: myvar.append( float(string_to_check) ) except: continue 如果结果是数字,则将myvar.apppend替换为要对字符串进行的任何操作。 这个想法是尝试使用float()操作并使用返回的错误来确定字符串是否为数字。 #3楼

Why is PyPy translate so slow?

馋奶兔 提交于 2019-12-09 15:54:15
问题 It takes hours to translate pypy implementation to c files and build the pypy-c on a modern notebook, with 2G mem and an Intel Core2 2GHz CPU. I know it's a cpu-intensive task, but does it have to be so slow? Is there any chance or room to reduce the computation, rearrange the computing order and cut the time to tens of minutes? 回答1: Disclaimer: I'm not an expert on PyPy - in particular, I don't understand the details of the RPython translation, I'm only citing docs and what overheared at the

multiprocessing Listeners and Clients between python and pypy

那年仲夏 提交于 2019-12-09 06:25:38
问题 Is it possible to have a Listener server process and a Client process where one of them uses a python interpreter and the other a pypy interpreter? Would conn.send() and conn.recv() interoperate well? 回答1: I tried it out to see: import sys from multiprocessing.connection import Listener, Client address = ('localhost', 6000) def client(): conn = Client(address, authkey='secret password') print conn.recv_bytes() conn.close() def server(): listener = Listener(address, authkey='secret password')

Using Pygame with PyPy

僤鯓⒐⒋嵵緔 提交于 2019-12-08 17:36:05
问题 I'm very new to python but I'd like to learn it by making games and pygame seems to be the best option. Since PyPy is the fastest implementation of python (I think) I decided to use that one. But I have no idea how to get those two working together. I'm on windows. If anyone would be so kind to give me a step by step on what I need to do I'd be really grateful. So far, I've installed (extracted to a folder) PyPy, set the pypy.exe as the default for opening .py files, installed Pygame and

Where's the GIL in PyPy?

会有一股神秘感。 提交于 2019-12-08 15:25:10
问题 Is the PyPy GIL part of the PyPy interpreter implementation in RPython, or is it something that translate.py automatically adds? i.e., if I were to write my own new language interpreter in RPython and ran it through translate.py, would it be subject to the GIL a priori, or would that be up to my interpreter code? 回答1: The GIL handling is inserted by module/thread/gil.py in your PyPy checkout. It's an optional translation feature and it's only added when thread module is enabled. That said,

how can I install numpy on pypy on my 64 bit computer running Windows 64 bit?

我的梦境 提交于 2019-12-08 10:44:03
问题 hardware/software: Machine 64 AMD processor running 64 bit windows I have a computationally heavy program that I wish to speed up by using Pypy. I have installed pypy and also installed Microsoft Visual Studio and Microsoft Visual C++ Build Tools. My python program uses Numpy so I tried to install numpy on pypy using the following pypy3 - m pip install numpy The error message I get says: error: Microsoft Visual C++ 14.1 is required. Get it with "Microsoft Visual C++ Build Tools": http:/

How can I embed a Python function that returns a string in C using cffi?

江枫思渺然 提交于 2019-12-07 22:07:07
问题 I'm trying to embed a Python function in C using PyPy and cffi. I'm following this guide from the PyPy documentation. The problem is, all the examples I've found operate on ints, and my function takes a string and returns a string. I can't seem to figure out how to embed this function in C, as C doesn't seem to really have strings, rather making do with arrays of chars. Here's what I've tried: # interface.py import cffi ffi = cffi.FFI() ffi.cdef(''' struct API { char (*generate_cool_page)

如何检查字符串是否为数字(浮点数)?

自古美人都是妖i 提交于 2019-12-07 18:16:25
检查字符串是否可以在Python中表示为数字的最佳方法是什么? 我目前拥有的功能是: def is_number(s): try: float(s) return True except ValueError: return False 不仅丑陋且缓慢,而且看起来笨拙。 但是我还没有找到更好的方法,因为在main函数中调用 float 更加糟糕。 #1楼 这个怎么样: '3.14'.replace('.','',1).isdigit() 仅当存在一个或不存在“。”时,它才返回true。 在数字字符串中。 '3.14.5'.replace('.','',1).isdigit() 将返回假 编辑:刚刚看到另一条评论...可以为其他情况添加 .replace(badstuff,'',maxnum_badstuff) 。 如果您传递盐而不是任意调味品(ref: xkcd#974 ),这将很好:P #2楼 这是我执行此操作的简单方法。 假设我正在遍历一些字符串,并且如果它们最终是数字,我想将它们添加到数组中。 try: myvar.append( float(string_to_check) ) except: continue 如果结果是数字,则将myvar.apppend替换为要对字符串进行的任何操作。 这个想法是尝试使用float()操作并使用返回的错误来确定字符串是否为数字。 #3楼