Installing and Running a NEO Blockchain Node using neo-python on Windows 10
Running neo-python on Windows can be a challenging task, and at current, appeared to be an impossibility. There are several dependencies that are unsupported on Windows that currently do not appear will have official support any time in the near future. Neo-python is constantly improving, so it’s possible that we will see these dependencies removed at some point in the future, but there are plenty of us that need to get up and running with neo-python today to take advantage of some of the unique functionality it provides.
This post will provide you with a step-by-step guide to running a neo-python node on Windows 10 using the Microsoft Windows Subsystem for Linux, but will also show you how you can attach Visual Studio Code to do interactive debugging.
A few notes before we get started:
This article includes instructions on the installation of the Windows Subsystem for Linux for users running Windows 10 Fall Creators Update (build 16215) or later. If you are running an older version, it may still be possible to install using lxrun (more info can be found here).
Chris Hager of City of Zion has done an excellent job of outlining How to run a private network of the NEO Blockchain using neo-python and neo-privatenet-docker. These instructions are the basis for a good portion of the configuration in this article, so it would be helpful to be familiar with them.
Setting Up the Windows 10 for Python Development
Install Python 3.6.3
https://www.python.org/downloads/release/python-363/
Note: Be sure to check the box on the installer to “Add Python 3.6 to PATH”
Install Git
https://git-scm.com/download/win
Install Visual Studio Code
https://code.visualstudio.com/download
Verify your Environment Variables / PATH include Python and Pip
Now that Python is installed, we still need to make sure that we have all the proper definitions in our PATH so we can access the scripts and executables we will need to build and run python applications.
To check your system PATH variables:
- Go to your Start Menu
- Type “Environment Variables”
- Choose “Edit the system environment variables”
- Go to the Advanced Tab and choose Environment Variables
- Select Path and Edit
You should have the following paths defined to allow you to use Python and Pip (if not, add them):
C:\<your_python_install_path>\Python36
C:\<your_python_install_path>\Python36\Scripts
Installing the Windows Subsystem for Linux (WSL)
For this article, we will be running Ubuntu on the Windows Subsystem for Linux to host neo-python.
Enable the Windows Subsystem for Linux (WSL)
- Go to theControl Panel
- Select Programs and Features
- Click the link to Turn Windows Features on or off
- Enable “Check Windows Subsystem for Linux” and Save (reboot if necessary)
Install Ubuntu from the Microsoft Store
https://www.microsoft.com/store/productId/9NBLGGH4MSV6
Setting up neo-python source code in Windows
Download Source with Git and Create Debug Copy on Windows
C:\> git clone https://github.com/CityOfZion/neo-python.git c:/<your_folder_path>/neo-python
Make a copy of the downloaded code for debugging
C:\> robocopy c:\<your_folder_path>\neo-python c:\<your_folder_path\neo-python-debug /s
The fun part about the WSL is that these paths we are working with from the Windows Environment are also available and mounted in the Ubuntu environment we just installed.
To see the code you just checked out in Windows when in Ubuntu (once running), simply go to the following paths:
>/mnt/c/<your_folder_path>/neo-python
>/mnt/c/<your_folder_path>/neo-python-debug
Configuring Ubuntu installed in WSL
As I mentioned before, these instructions have been outlined in detail. These instructions will get you running neo-python on Ubuntu, but there are a few minor changes we need to make to make this easier for debugging on Windows.
Set up Your Account
Launch Ubuntu from Windows and Create Account when Prompted
Configure and Install neo-python
Configure and install neo-python as outlined in the instructions here. Be sure not to use the docker image method, and configure / setup the copy of the code you checked out previously in Windows located at:
>/mnt/c/<your_folder_path>/neo-python
Once you have neo-python running on Ubuntu successfully, you can proceed to enable remote debugging.
Setting Up to Debug from VSCode on Windows
Open Source Code Folder in VS Code
- Go to the top File Menu
- Select Open Folder
- Browse to C:\<your_folder_path>\
- Select folder \neo-python
Select the file that you want to debug from folders that just opened
ie: C:\<your_folder_path>\neo-python\<file_to_debug>
Select Debug Version of the File you want to debug
- Go to the top File Menu
- Select Open File
- Browse to C:\<your_folder_path>\neo-python-debug\
- Select <file_to_debug>
Add Debug Server Code to Both Files
Both pieces of code have to match for the debugger to work properly. The “posix” OS identifier lets us know to only start the debugging server on Ubuntu.
At the top of both source files, include the following:
import os
if os.name == “posix”:
import ptvsdptvsd.enable_attach(“uniquecodeforsecurity”, address = (‘127.0.0.1’, 3000))
print(“Waiting for debugger to attach…”)
ptvsd.wait_for_attach()
ptvsd.break_into_debugger()
This lets the executing code know that if we’re running on Ubuntu, to start a debugging server/listener on port 3000 (since we are on WSL it’s all localhost so we don’t have to mess with firewalls and ports), and wait for a debug request to come in.
Add the Python Remote Debug Configuration to VS Code
- Open the Debug Tab
- Click the Settings Wheel
- Add the Remote Debug Configuration to launch.json in the Configurations array{“name”: “Attach (Remote Debug)”,
“type”: “python”,
“request”: “attach”,
“localRoot”: “${workspaceFolder}”,
“remoteRoot”: “/mnt/c/<your_folder_path>/neo-python-debug”,
“port”: 3000,
“secret”: “uniquecodeforsecurity”,
“host”: “127.0.0.1”},
Start Debugging
Finally! There were a lot of steps here, but now we can finally run our code in a full Ubuntu environment giving us full dependency support for neo-python. Now the rest is simple, we just need to fire up the code!
Start the Program on Ubuntu WSL
> python3 ./mnt/c/<your_folder_path>/neo-python-debug/<file_to_debug>
Go to VS Code and Start Debugging on Windows
- Focus the non-debug source file (ie: neo-python/<file_to_debug>)
- Select the debug tab
- Select the profile we created earlier “Attach (Remote Debug)” from dropdown
- Start debugging
And that’s it! You should be up and running your neo-python node in Ubuntu while debugging in Visual Studio Code on Windows.
Need additional help?
The technique we used here to enable a remote debugging session across Windows and WSL can also be used with remote servers. I guarantee once you start working with remote debugging, you will find it a handy tool for those times where “it works on your machine”, but something entirely different is happening on a test or production environment.
City of Zion
If you need further assistance in getting started, feel free to join the City of Zion NEO Smart Economy Discord Server. The community will help you get set up and debugging your smart contracts in no time.