Adding library in PYTHON embeded
Posted: Wed Feb 03, 2016 10:09 am
Hello at all
Thanks to Epidemicz and Infratec
http://www.purebasic.fr/english/viewtop ... 61#p335161
I learn it's possible to use PYTHON with PB
For do what ? can use OOP library with PB
I want use SELENIUM and it's the only one more simple way for me i have found
So since 2 days i try to understand this code
And i have adding 3 new functions, (It's already a miracle
) Get the version of the DLL, Get the compiler and mainly launch a script PY
So now i try to adding the library SELENIUM
I have found a code in C here
http://stackoverflow.com/questions/9814 ... -directory
But that's not works
I have a IMA at the line
If someone have understand how do that
Have a good day
Thanks to Epidemicz and Infratec
http://www.purebasic.fr/english/viewtop ... 61#p335161
I learn it's possible to use PYTHON with PB

For do what ? can use OOP library with PB
I want use SELENIUM and it's the only one more simple way for me i have found
So since 2 days i try to understand this code
And i have adding 3 new functions, (It's already a miracle


Code: Select all
PrototypeC Py_Initialize()
PrototypeC.s PyRun_SimpleString(String.s)
PrototypeC.l Py_GetVersion()
PrototypeC.l Py_GetCompiler()
PrototypeC Py_Finalize()
If OpenConsole()
If OpenLibrary(0, "python31.dll")
PythonInitialize.Py_Initialize = GetFunction(0, "Py_Initialize")
PythonRunSimpleString.PyRun_SimpleString = GetFunction(0, "PyRun_SimpleString")
PythonGetVersion.Py_GetVersion = GetFunction(0, "Py_GetVersion")
PythonGetCompiler.Py_GetCompiler = GetFunction(0, "Py_GetCompiler")
PythonFinalize.Py_Finalize = GetFunction(0, "Py_Finalize")
PythonInitialize()
pystring$ = "import os" + Chr(10)
pystring$ + "os.system('navigation_Illico.py')"
Debug PythonRunSimpleString(pystring$)
; Obtenir la version
*Ptr = PythonGetVersion()
Debug PeekS(*Ptr)
; Obtenir le compiler utilisé pour construire la version PYTHON
*Ptr = PythonGetCompiler()
Debug PeekS(*Ptr)
PythonFinalize()
CloseLibrary(0)
Delay(3000)
EndIf
CloseConsole()
EndIf
I have found a code in C here
http://stackoverflow.com/questions/9814 ... -directory
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>
int main(void)
{
const char *scriptDirectoryName = "/tmp";
Py_Initialize();
PyObject *sysPath = PySys_GetObject("path");
PyObject *path = PyString_FromString(scriptDirectoryName);
int result = PyList_Insert(sysPath, 0, path);
PyObject *pModule = PyImport_ImportModule("userscript");
if (PyErr_Occurred())
PyErr_Print();
printf("%p\n", pModule);
Py_Finalize();
return 0;
}

Code: Select all
PrototypeC.l PySys_GetObject(String.s)
PrototypeC.l PyString_FromString(String.s)
PrototypeC.i PyList_Insert(Objet.l, Integer.i, Chemin.l)
PrototypeC.i PyImport_ImportModule(String.s)
PythonGetObject.PySys_GetObject = GetFunction(0, "PySys_GetObject")
PythonString_FromString.PyString_FromString = GetFunction(0, "PyString_FromString")
PythonList_Insert.PyList_Insert = GetFunction(0, "PyList_Insert")
PythonImport_ImportModule.PyImport_ImportModule = GetFunction(0, "PyImport_ImportModule")
*sysPath = PythonGetObject("path")
*path = PythonString_FromString("D:/Temp/Python/selenium")
result = PythonList_Insert(*sysPath, 0, *path)
*pModule = PythonImport_ImportModule("selenium")
Code: Select all
*path = PythonString_FromString("D:/Temp/Python/selenium")
Have a good day