Pymgclient error while following a guide

Hi all,

I was following a quick-start guide (Python - Docs) for Python application from docs and facing an issue while building a python image.

From what I understand it looks like a “C” error from pymgclient database adapter itself.

Any help would be appreciated.

Thank you.

Greetings!

1 Like

Hi, first of all thank you for posting this problem!

Our pymgclient uses our C client called mgclient.
A few days ago we’ve updated the pymgclient and now it uses a newer version of mgclient. As you can see in the Dockerfile, a specific commit is used for the mgclient while the pymgclient just fetches the latest version. Because of that, the docker tries to build new pymgclient with the older version of mgclient.
The problem can be fixed by changing the commit in the Dockerfile for the mgclient to the commit of the newest version, 1.2.
So this part:

RUN apt-get install -y git cmake make gcc g++ libssl-dev && \
  git clone https://github.com/memgraph/mgclient.git /mgclient && \
  cd mgclient && \
  git checkout 5ae69ea4774e9b525a2be0c9fc25fb83490f13bb && \
  mkdir build && \
  cd build && \
  cmake .. && \
  make && \
  make install

should be:

# Install mgclient
RUN apt-get install -y git cmake make gcc g++ libssl-dev && \
  git clone https://github.com/memgraph/mgclient.git /mgclient && \
  cd mgclient && \
  git checkout dd5dcaaed5d7c8b275fbfd5d2ecbfc5006fa5826 && \
  mkdir build && \
  cd build && \
  cmake .. && \
  make && \
  make install

Please try it out and tell us if it works! :smiley:

1 Like

Thanks for a quick response, Toni. It works now! :smiley:

However, just a question from docs: Why does the output say “Node 2: Hello World!” instead of it being the first node created? According to the guide, it should have been “Node 1”.

Referring to this part :

# Create a node with the label FirstNode and message property with the value "Hello, World!"
query = """CREATE (n:FirstNode)
           SET n.message = '{message}'
           RETURN 'Node '  + id(n) + ': ' + n.message""".format(message="Hello, World!")

# Execute the query
cursor.execute(query)

# Fetch one row of query results
row = cursor.fetchone()

# Print the first member in row
print(row[0])

Sorry if this question is too silly but I am trying to learn & implement Memgraph as part of my Thesis. :slight_smile:

Thank you again!

1 Like

Sorry if this question is too silly but I am trying to learn & implement Memgraph as part of my Thesis. :slight_smile:

Not at all, nice to see you’re giving Memgraph a chance!

Why does the output say “Node 2: Hello World!” instead of it being the first node created? According to the guide, it should have been “Node 1”.

Because the id() function returns the internal id of the vertex. Maybe you have data leftover from the previous runs which you deleted? Each time you create a vertex, you increase the internal id, but if you delete the vertices, the id won’t decrease.
E.g. I create a vertex, it gets id = 1
I delete the vertex
I create a new vertex, it gets id = 2, even though it’s the only vertex in the database.
You can see this by running the memgraph_python multiple times, the id should increase each time by one even though you’re dropping all the vertices and edges at the start of the script.
Also, if you delete all the vertices and stop the Memgraph instance (which should create a snapshot if you’re using the default configs), starting the instance again will set the counter on the initial value and you should see “Node 1”.

1 Like

Got it! Thank you very much for such an easy explanation.

I will keep exploring Memgraph. :smiley:

Greetings!

1 Like

At this point, pymgclient does not ensure that there is the right version of mgclient. Here is a PR to improve the compile experience (work in progress).

@red_devil thank you for the feedback!