Download Windows embeddable package .zip file from Python download page.
If you use 64-bit TNG then you need 64-bit Python version.
If you use 32-bit TNG then you need 32-bit Python version.
Unzip .zip file to folder where your embeddable Python will be. In my case this is 'C:\Python\python-3.11.2-embed-win32'.
Open folder and find main library .dll file. In my case it is 'python311.dll'. If you use different Python version it will be different but similar.
Full path is therefore 'C:\Python\python-3.11.2-embed-win32\python311.dll'.
Open TNG, go to settings and set this path as 'Python Library'.
Check if installation was successful and that Python is available to TNG by clicking 'Check' button. You should see dialog showing your Python version.
If Python is available then you can use it with TNG. It is recommended that you restart TNG after changing 'Python Library' setting.
Python can use various 3rd party modules. To use them, you need to install them to your embedded Python.
This is done with command prompt. Open new command prompt using 'Run' and then typing 'cmd.
Change directory to your embedded Python installation with 'cd' command.
In my case it is:
Check that Python is working by using command:
You should see your Python version.
Then you need to install PIP. PIP is package manager used by Python to install modules.
To do this you need to download file named 'get-pip.py' from https://bootstrap.pypa.io/get-pip.py.
You can use 'curl' command which is included with Windows 10. You can also use other way to get this file.
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Make sure that get_pip.py file was successfully downloaded.
Install PIP using command:
Make sure installation was successful.
If it was then pip.exe is located in subfolder named 'Scripts'.
Open 'python311._pth' file with text editor.
Add two path lines lines:
Uncomment (remove # character) from line 'import site':
It should look like this:
python311.zip . .\Lib .\Lib\site-packages # Uncomment to run site.main() automatically import site
Now we can use PIP to install Python modules.
I will install 'NumPy' which offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more.
.\Scripts\pip.exe install numpy
Make sure there were no errors:
I will also install 'OpnenCV' which is a real-time optimized computer vision library.
.\Scripts\pip.exe install opencv_python
Make sure there were no errors:
You have successfully added two modules you your embedded Python installation.
You can create Python script to check if 'OpenCV' runs correctly. You need webcam for this test to work.
Create test file in your Python folder named 'cvtest.py'.
Add this content:
import cv2 cap = cv2.VideoCapture(0) while(1): # Capture image ret, image = cap.read() #cv2.imshow('Camera',image) # Convert image to grayscale img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #cv2.imshow('Gray',img_gray) # Find canny edges edges = cv2.Canny(img_gray, 30, 200) # Find contours contours, hierarchy = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) #cv2.imshow('Edges',edges) # Draw all contours (-1 means drawing all contours) cv2.drawContours(image, contours, -1, (0, 255, 0), 1) cv2.imshow('Contours', image) if ((cv2.waitKey(1) & 0xFF) == ord('q')): break cv2.destroyAllWindows() cap.release()
Save file and run it with with:
After few seconds window with 'OpenCV' video stream will show.