Python Forum

Full Version: problem with memory_graph module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi
code:
# from:https://pypi.org/project/memory-graph/
'''
custom copy method
We can write our own custom copy function or method in case the
three "copy" options don't do what we want. For example the
copy() method of My_Class in the code below copies the numbers
but shares the letters between the two objects.
'''

import memory_graph
import copy
import os

class My_Class:

    def __init__(self):
        self.numbers = [1, 2]
        self.letters = ['a', 'b']

    def copy(self): # custom copy method copies the numbers but shares the letters
        c = copy.copy(self)
        c.numbers = copy.copy(self.numbers)
        return c

a = My_Class()
b = a.copy()
print(a.numbers,b.numbers)
print(a.letters,b.letters)
a.numbers=[100,100]
print(a.numbers,b.numbers)
print(a.letters,b.letters)
a.letters[0]='a_changed'
print(a.numbers,b.numbers)
print(a.letters,b.letters)

myfile="memory_graph.gv.pdf"
if os.path.isfile(myfile):
    os.remove(myfile)
memory_graph.show(locals())
first, consider the above code and comment on the if condition and its block.
the code is run truly and creates a file as "memory_graph.gv.pdf"
if I run again the code, because of the presence above file in the same directory, errors appear. because the number of error lines is larger than 30, so I do not include it here.
I want to delete the mentioned file before the memory_graph.show(locals()) line is run, so I write the if block to delete the file. but the below error appears:
Error:
Traceback (most recent call last): File "D:\akb_python\akb_py_projects\memory_graph\custom_copy.py", line 38, in <module> os.remove(myfile) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'memory_g raph.gv.pdf'
what can I do to correct the code?
thanks
Maybe you can't. Does this only happen when you try to do view two memory graphs at the same time? If so, my guess is the viewer left memory_graph.gv.pdf open.

I tried running your program, but memory-graph doesn't run on my windows computer with python 3.11.
(Mar-03-2024, 03:44 PM)deanhystad Wrote: [ -> ]Maybe you can't. Does this only happen when you try to do view two memory graphs at the same time? If so, my guess is the viewer left memory_graph.gv.pdf open.

I tried running your program, but memory-graph doesn't run on my windows computer with python 3.11.

hi
thanks for reply
according tohttps://pypi.org/project/memory-graph/ I installed memory_graph with pip and also a small app with the name graphviz must be installed.I have python 3.11.5 in my pc(win 10).
It works fine for me when i test most run 2 times for it two overwrite memory_graph.gv.pdf.
If i want to save a graph just rename to eg factorial_grah.pdf.
Then when run again a new graph will be again in the default memory_graph.gv.pdf.
I think your problem arises because your PDF reader (probably Adobe Acrobat Reader) blocks any change to and deletion of each file it has open. To solve your problem:
- first close the PDF reader so that it stops blocking
- use a PDF reader that doesn't block (Evince?)
- render to a different format and open manually: memory_graph.render(locals(), "my_graph.png")
- complain to Adobe so they stop blocking (I already tried, didn't work)

See the memory_graph troubleshooting section: https://github.com/bterwijn/memory_graph...leshooting
(Jan-14-2025, 04:00 PM)bterwijn Wrote: [ -> ]See the memory_graph troubleshooting section
Congrats for the memory_graph module, it looks pretty neat. I just starred it in github. It reminds me of a small module named lumpy (part of swampy) that existed already in the good old times of Python 2. It must be at least 15 or 20 years old!