Installation and Setup
Last updated
Last updated
This section shows you how to run the service from the command line, which is useful for testing, and how to run as a service which is more suited to a production environment.
The Python Rest Service along with the Python enrichment steps can be found in the InsightMaker.Python distribution.
Note that this guide assumes you are familiar with Python.
First configure the enrichment steps that you want to activate by editing the config/endpoints.json file. Simply add and/or remove the ones that you want to use.
The following steps are required to get an instance running on the command line. It is recommended that you first get the service running on the command line so you can easily resolve any issues. Once this runs correctly and you have tested it with a test enrichment pipeline then you can optionally run the service as a Window service.
Before starting, check to see if there is already a version of Python running on the server. You can do this by checking the PATH and the location of installed applications.
Option 1 – Install Python where no other Python version exists on the server:
Install Python 3.9.13
You need to install Python for ‘all users’ if you plan to run the Python REST Service as a Window Service.
Create a Python ‘virtual environment’:
Create a venv folder in the root of the PythonRestService folder.
Open a command prompt, navigate to the venv folder, and create the venv with the following python command:
python -m venv ./
Option 2 – Install Python where other Python versions exist on the server:
Install Python 3.9.13
You need to install Python for ‘all users’ if you plan to run the Python REST Service as a Window Service.
Do not add select add to the system variables or path (this may interfere with existing Python applications running on the server)
Open an administrator command prompt and install virtualenv
pip install virtualenv
Create a Python ‘virtual environment’:
Create a venv folder in the root of the PythonRestService folder.
Open a command prompt, navigate to the venv folder, and create the venv with the following python command:
python -m virtualenv ./ -p="C:\Program Files\Python39\python.exe"
Replace the -p parameter with the path to the Python 3.9.13 executable
Configure and install prerequisites:
Ensure long path support is enabled – use regedit to do this:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
LongPathsEnabled
DWORD = 1
Activate your Python virtual environment:
Activate your virtual environment by navigating to the venv/Scripts folder and running activate.bat
You should now see (venv) at the start of your command line.
See this Python guide for creating a venv: https://docs.python.org/3/tutorial/venv.html
On the command line navigate back to InsightMaker.Python\PythonRestService
Open the the requirements_<x.x.x>.txt file and check that the following line is not in the file, and if it is remove it:
en_core_web_sm==xxx
(where xxx is the version number)
Python Torch has some run-time prerequisites.
For Windows, the prerequisites for torch include the Visual Studio runtime – install this.
For other OS please see: https://pypi.org/project/torch/
Use ‘pip’ to install all the requirements in the latest requirements file:
Online:
pip install -r requirements_3.9.13.txt
Offline:
On an internet conenected machine:
Create a temporary folder.
Navigate to the temporary folder.
pip download -r requirements_3.9.13.txt
Copy the resulting contents of the temporary folder to the target server.
Run the following on the target server, replacing the path to the temporary folder as appropriate.
pip install --no-index --find-links C:/tmp/libs -r requirements_3.9.13.txt
Run the following to install the Spacy models (if you are using this enrichment step):
python -m spacy download en_core_web_sm
Install the NLTK data (models) to a location on the server:
Note, if you do not have an internet connection, run the following commands on a machine that does, and then copy the NLTK data to the target server. Remember to also recreate the environment variable on the target server.
python -m nltk.downloader all -d <DRIVE:/LOCATION>
Set an environment variable to point at the NLTK data:
NLTK_DATA=DRIVE:/LOCATION
Occasionally ‘omw-1.4’ is missing – run this to double check. It will install it if it is missing.
python -m nltk.downloader omw-1.4
The guide is here for NLTK: https://www.nltk.org/data.html
Edit run.bat in the root of ‘InsightMaker.Python\PythonRestService’ to point at the correct location for your virtual environment and Python Rest Service
Exit the virtual environment and open a new command window and navigate to the ‘InsightMaker.Python\PythonRestService’ folder.
If you are running on a server without an internet connection, open the config/endpoints.json
file and remove huggingfacener.
We can get this working once we have tested the installation thus far. This is covered in the ‘Offline Huggingface Set-up’ section.
Edit the ‘run.bat’ so that it contains an absolute path to the ‘waitress_server.py’ file and your virtual environment
Execute ‘run.bat’ on the command line. You should see the output as shown below.
This should activate your virtual machine and start the service
Make sure you are in the root folder of the Python Rest Service
If you navigate to http://localhost :15005/ you should see this in the browser.