Does neo4j work with WSL2?

Hi everyone!

The problem: I get an errno 111: no connection between the python client and the activated neo4j graph db. Same situation with both py2neo and neo4j python driver

The setup: WSL2 (build 4.19.121.1) with Ubuntu 18.04 LTS, on windows 10 Pro insider preview (build 20152.rs_prelease.200617-1502)

On WSL2, a conda env was created with py2neo, rapidsai, etc. On windows, neo4j and pycharm are installed. The code is written in pycharm and as an interpreter I use the conda env from WSL2. However, every time I'm trying to run a query, I get an errno 111 error message. Queries from the neo4j interface run smoothly.

The code:

  1. graph = Graph("bolt://localhost:7687", auth=("user", "pass"), max_connection_lifetime=200)
  2. q1 = """ CALL apoc.periodic.iterate( "MATCH (n:Person) RETURN n", "DETACH DELETE n", {batchSize:1000})
    """
  3. output = graph.run(q1).to_data_frame()

The problem appears in line 3. What would cause this issue?

Neo4j desktop 1.2.9
DB version: 3.5.17 and 3.5.19 were tried

Thanks!
Andreas

Sounds like there is some sort of connectivity issue.

Do I understand it correctly if I think the database is running natively in Windows and your script in the WSL environment?

Not familiar with WSL at all but I would suspect that the localhost of WSL is a different one than the windows environment. Perhaps I am completely wrong though, haven't seen Windows from up close for over 15 years.

However that 111 error is a Python connection error, I would dig into that direction.

1 Like

WSL works with a neo4j docker instance.

It does not work with Neo4j desktop instances. Not sure why it fails even with all of the configuration matching for the docker image. Probably something related to the bolt protocol.

Steps to get it working

  1. Install docker and make sure WSL support is enabled
  2. Have a neo4j docker instance docker pull neo4j:latest

Run this in docker to connect your WSL ports correctly.

# This script spins up a docker instance

INSTANCE_NAME="neo4j-server"
PASSWORD="your-password"

docker run \
--name $INSTANCE_NAME \
-p7474:7474 -p7687:7687 \
--env NEO4J_dbms_connector_https_advertised__address="localhost:7473" \
--env NEO4J_dbms_connector_http_advertised__address="localhost:7474" \
--env NEO4J_dbms_connector_bolt_advertised__address="localhost:7687" \
--env NEO4J_AUTH=neo4j/$PASSWORD \
neo4j:latest
  1. Connect to localhost with your WSL server and it should resolve correctly.
1 Like

Errno 111 is "Connection refused". So, my guess is there is some permissions problem, such that the DB is not happy with the client that's trying to connect to it.

Maybe bad config or bad username/password?

1 Like

Hi @and.manousakis, at which environment you are getting this error ? on the WSL2 or on Windows ? Also, you mentioned py2neo is installed only in conda, but I am sure you have already installed in windows also.

Also, since you mentioned WSL2, I believe you have docker also installed. So, follow @FrederickEngelhardt steps, but be sure to mount the volume to persist the data. Since you are using Neo4j 3.5, feel free to download my image and the docker-compose file

Let me know if you need further assistance.

1 Like

Hi @FrederickEngelhardt, thanks for the answer! I would try your suggestion if I hadn't switched to linux.

In case I switch back to that setup I'll give it a try :)