Python Memory Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About python memory error increase memory Us Learn more about Stack Overflow the company Business Learn more about hiring python memory error numpy developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the memory error python pandas Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why Python `Memory Error` with list how to solve memory error in python `append()` lots of RAM left up vote 16 down vote favorite 5 I am building a large data dictionary from a set of text files. As I read in the lines and process them, I append(dataline) to a list. At some point the append() generates a Memory Error exception. However, watching the program run in the Windows Task Manager, at the point of the crash I see
Python Memory Error Large Array
4.3 GB available and 1.1 GB free. Thus, I do not understand the reason for the exception. Python version is 2.6.6. I guess, the only reason is that it is not able to use more of the available RAM. If this is so, is it possible to increase the allocation? python list memory share|improve this question asked Dec 14 '10 at 17:07 Pete 5,12062140 1 Try using a 64-bit build of Python. Though if you are using any extension modules, they'll then need to be built 64-bit as well. –Adam Vandenberg Dec 14 '10 at 17:08 Can you print the MemoryError exception string? That should give us more info. –chrisaycock Dec 14 '10 at 17:10 Are you appending before or after you process the lines? –nmichaels Dec 14 '10 at 17:15 @nmichaels- looks like this: data.append(processraw(raw)). each raw is one line. –Pete Dec 14 '10 at 17:36 Show us more code and maybe we will be able to show you how to improve your memory consumption. How big is your set of text files? @aix is right about 32-bit versus 64-bit. –kevpie Dec 14 '10 at 18:01 add
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and
Python Increase Memory Limit Windows
policies of this site About Us Learn more about Stack Overflow the company python range memory error Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users python memory error reading file Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a http://stackoverflow.com/questions/4441947/why-python-memory-error-with-list-append-lots-of-ram-left minute: Sign up Is there a way to avoid this memory error? up vote 7 down vote favorite 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 http://stackoverflow.com/questions/16091781/is-there-a-way-to-avoid-this-memory-error 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 "done finding combinations", time.time() - start sums = map(lambda x: x[0]+x[1], pairs) print "done finding all possible sums", time.time() - start print "start main loop" answer = 0 for i in range(1,limit+1): if i not in sums: answer += i print "ANSWER:",answer When I run this I run into a MemoryError. The traceback: File "test.py", line 20, in
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://programmers.stackexchange.com/questions/269961/facing-memoryerror-in-python About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Software Engineering Questions Tags Users Badges Unanswered Ask Question _ Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle who care about creating, delivering, and maintaining software responsibly. Join them; it only memory error takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Facing MemoryError in Python up vote 0 down vote favorite I wrote a program to find prime factors of a number. When I give a large number(600851475143) as input, MemoryError pops up. Below is the code: def fact(a): python memory error factors = [] for i in range(1,a+1): if a%i == 0: factors.append(i) return factors num = raw_input(">> ") #600851475143 a = b = [] a = fact(long(num)) for i in range(0,len(a)): b = fact(a[i]) if len(b) <= 2: print a[i] From browsing I came to know that Python makes use of Computer memory - RAM. I am using Python in Unbuntu without changing its configuration. Should I change anythig to work on 64-bit machine. Or should I use any additional function(s) to get around this error python memory error-messages share|improve this question asked Jan 13 '15 at 18:47 Gdek 313 4 Your basic issue is that your algorithm is likely using too much memory. If you are using python 2, then range(1, a+1) is attempting to create a list with 600851475143 elements. This is probably not what you want as each element will be an integer and each integer takes 4 bytes. (Also, this question isn't appropriate for Programmers as you really need a code review and to understand in particular how python works.) –Steven Burnap Jan 13 '15 at 18:56 (You probably want xrange, which is a generator that returns e