Memory Error Python while processing large database - python

When I run this on Pycharm 4 on windows I got an error in this code:
PDBSumWWW = urllib.urlopen("https://www.ebi.ac.uk/thornton-srv/databases/pdbsum/data/seqdata.dat")
PDBSum = PDBSumWWW.read().splitlines()
PDBSumWWW.close()
This is the error message:
Traceback (most recent call last):
File "C:/Users/LuisAlberto/PycharmProjects/MSc/SeqPDBSumIRIndex.py", line 98, in
main()
File "C:/Users/LuisAlberto/PycharmProjects/MSc/SeqPDBSumIRIndex.py", line 40, in main
PDBSum = PDBSumWWW.read().splitlines()
MemoryError
However when running in on a Macbook Air it doesnt happen.
how do I get over this?

This is the most simple solution that I can think of to solve your problem.
In this solution the for loop will iterate over every line in the database.every line will be assigned to the line variable.
PDBSumWWW = urllib.urlopen("https://www.ebi.ac.uk/thornton-srv/databases/pdbsum/data/seqdata.dat")
for line in PDBSumWWW:
# Do necessary calculations.
PDBSumWWW.close()

Related

CS50 - debug50 isn't working after update

runoff/ $ debug50 ./runoff a b c
Launching VS Code debugger...
Traceback (most recent call last):
File "/usr/local/bin/debug50", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/debug50/__main__.py", line 72, in main
asyncio.get_event_loop().run_until_complete(launch(args.PROGRAM, extra_args))
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/usr/local/lib/python3.10/site-packages/debug50/__main__.py", line 90, in launch
source = list(filter(lambda source_file: program in source_file, get_source_files(program)))[0]
IndexError: list index out of range
After I updated the web IDE for CS50, I keep getting this error whenever I try to launch debug50. I don't know what to do. It was working just fine.
Obs: I'm setting the breakpoints, I didn't miss this part.
I ran into this same issue. I'm wondering if an update to debug50 has been made. Here's how I got it to work.
Try omitting the ./ from your command line script, so long as you are in the directory containing your program.
e.g.
debug50 runoff a b c

pyautogui.pixel works perfectly for a while, and then randomly stops working and gives errors

I have been implementing pyautogui.pixel in many forms of code, I will get a normal desirable output for a random short while, and at some point, the function will stop working, and I will get error messages.
Simple example code:
while True:
print(pyautogui.pixel(1766, 1539))
Output:
(30, 30, 30)
The eventual error message:
Traceback (most recent call last):
File "c:\Users\zyoli\Desktop\scrap_bot\gathering.py", line 14, in <module>
print(pyautogui.pixel(1766, 1539))
File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 584, in pixel
return (r, g, b)
File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 124, in __exit__
next(self.gen)
File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 113, in __win32_openDC
raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0
I suppose you are switching some windows/app while running the code. Maybe because of the animation(while opening a new window), Pyautogui raises an error. get_pixel from the screen is slow. Maybe this thread can help you:
Quickly getting the color of some pixels on the screen in Python on Windows 7

I get an error "MemoryError" in Python. When I find association rules and keep in list()

This code:
assoc_rules = apriori(records_mongo, min_support=0.5)
assoc_result = list(assoc_rules)
And when I run this code, Result show -
Traceback (most recent call last):
File "E:/mongodb_python/app2.py", line 54, in assoc_result = list(assoc_rules)
File "E:\mongodb_python\venv\lib\site-packages\apyori.py", line 288, in apriori
for support_record in support_records:
File "E:\mongodb_python\venv\lib\site-packages\apyori.py", line 203, in gen_support_records
candidates = _create_next_candidates(relations, length)
File "E:\mongodb_python\venv\lib\site-packages\apyori.py", line 157, in create_next_candidates
return list(tmp_next_candidates)
MemoryError
Apriori can be very memory intensive when you use a to low minimum support.
Also, do not use apyori. Last I checked it was just crappy code, incomplete and not implementing the Apriori algorithm. There are many bad libraries out there! Use pyfim instead.

Did pyglet change recently?

So, The other day, I went back to an old project to finish it but when I tried running it, it gave me several errors that I've tried to fix but some of them I don't know how to fix. The program worked fine when I stopped working on it, so I'm very confused at what happened. My guess is that pyglet got a new update and removed a lot of stuff I used to use. Some of the errors I get are as follows
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 9,
in <module>
screen =
pyglet.window.get_platform().get_default_display().get_default_screen()
AttributeError: module 'pyglet.window' has no attribute 'get_platform'
and
Traceback (most recent call last):
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 216, in <module>
main()
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 208, in main
win = Window(caption = "3D Program 1", width = WINW, height = WINH, resizable = False, vsync = True)
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 57, in __init__
self.tex1 = get_tex("steel_tex.png")
File "C:\Users\____\Desktop\Code\3D\Projects\3D Program 1\main.py", line 21, in get_tex
tex = pyglet.image.load(file).texture
AttributeError: 'ImageData' object has no attribute 'texture'
I also had problems with it saying that there was no such thing as the "pyglet.graphics.TextureGroup" class
Yes, it looks like both of snippets of code you show are using features that were deprecated in previous versions of Pyglet and removed in the recent 1.4 release. You can see the deprecation (and their suggested replacements) in the documentation for older versions:
The get_platform() function in pyglet.window:
Deprecated. Use pyglet.canvas.Display.
The .texture attribute of an image:
Deprecated. Use get_texture().

PANDA3D: Sound Error

I can't seem to be able to execute mon Main.py because it's giving me this error:
Traceback (most recent call last):
File "main.py", line 383, in <module>
gamebase = GameBase()
File "main.py", line 278, in __init__
DGG.setDefaultRolloverSound(self.sounds['GUI_rollover'])
KeyError: 'GUI_rollover'
:TaskManager: TaskManager.destroy()
(for sure, it's sound related... and dict related, but i cant seem to figure out where the problem is)
The part where the error occur is right here:
exts = ('mp3','wav','ogg')
for x in (3,3.5,5,0):
for ext in exts:
for s in ToonGlobber.glob("phase_"+str(x)+"/audio/sfx/GUI_*."+ext,"phase_"+str(x)+"/audio/sfx"):
sf = s.split('/')[-1].split('.')[0]
self.sounds[sf] = loader.loadSfx(s)
DGG.setDefaultRolloverSound(self.sounds['GUI_rollover'])
DGG.setDefaultClickSound(self.sounds['GUI_click'])
self.pickerNode = CollisionNode('mouseRay')
self.pickerNP = camera.attachNewNode(self.pickerNode)
self.pickerNode.setIntoCollideMask(BitMask32.allOff())
self.pickerNode.setFromCollideMask(BitMask32(16))
self.pickerRay = CollisionRay()
self.pickerNode.addSolid(self.pickerRay)
What's causing this? What can be done to fix it?
It cannot find the named sound files, presumably because the phase MF is not properly mounted or does not contain the given GUI sounds.

Categories

Resources