Adding library in PYTHON embeded

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Adding library in PYTHON embeded

Post by Kwai chang caine »

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 8)

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 :shock:) Get the version of the DLL, Get the compiler and mainly launch a script PY :D

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
So now i try to adding the library SELENIUM
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;
}
But that's not works :cry:

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")
I have a IMA at the line

Code: Select all

*path = PythonString_FromString("D:/Temp/Python/selenium")
If someone have understand how do that

Have a good day
ImageThe happiness is a road...
Not a destination