Embedding Python into your apps

Share your advanced PureBasic knowledge/code with the community.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Embedding Python into your apps

Post by Kwai chang caine »

You have right, but in my case, it's just for use SELENIUM the remote webbrowser.
Unfortunately (for me and PB), the creator have create an OOP language :|

So obviously, all his library is OOP and then impossible to use with PB
The great SROD have create COMATE for the community, starting to Dishelper made in C
Before, i use COMATE for remote IE, and all it's done 8)
But now, IE is not always updated on all machine, and sometime not accept all the last HTML, and mainly, IE is not portable :|

A friend show me PYTHON with SELENIUM for FF for replace COMATE and OLE for IE, and i must recognize that's works nearly also good than COM
It's the reason why, i'm forced to try to embeding PYTHON for use SELENIUM and FF all that in portable version.

For me, the dream is always everybody coding in C, but we know you and me it's not the case.
The C is always in the most used language, but all the new library, and other languages (C++, c#, JAVA, PYTHON, PHP, etc ..) is OOP, and i'm sad about that :cry:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Embedding Python into your apps

Post by Kwai chang caine »

I don't understand...i'm really a donkey :oops:

Image
I have :
1/ Install Python 3.1.4
2/ Take the "Python31.dll"
3/ Uninstall Python
4/ Compile your code in console mode with "callpy.exe" with PB v4.51
5/ Put "callpy.exe" + python31.dll + first.py on root of C:
6/ Write "callpy first multiply 2 3" on the root in the cmd console

And i have this error with XP pro :oops:
C:\>callpy first multiply 2 3
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named encodings.utf_8
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Embedding Python into your apps

Post by infratec »

Hi KCC,

copy callpy.exe first.py and the dll in one directory.

I compiled callpy.pb in ascii mode.

hmm....

Just tried it on my home PC: same result as you.
Strange I use the same OS (Win7 Pro X64) in the office: works like charme.

I'll have look...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Embedding Python into your apps

Post by Kwai chang caine »

Alleluia !!!!
I'm not alone to have this problem 8)

You surely laugh but i have even thinking, with my little head to try to compile in UNICODE, without succes too, obviously :oops:
I'll have look...
You are an angel 8)
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Embedding Python into your apps

Post by infratec »

Some hints from the web means: a wrong PYTHONHOME environment variable
But I'd looked everyywhere (set, registry) there is nothing to find.

An other point is VC9 runtime environment.
The dll is compiled with vc9 and it needs the vc9 runtime environment.
it's in vc 2008 redist stuff.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Embedding Python into your apps

Post by Kwai chang caine »

Thanks a lot i take a look about this VC9
Me since the beginning i have the same error, even with the W7 of my office
With XP it's more understandable, but with W7....
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Embedding Python into your apps

Post by Kwai chang caine »

It's strange, because i have two VC++ 2008 redistributable installed on my XP :shock:
And that works not two time better :lol:
ImageThe happiness is a road...
Not a destination
smacker
User
User
Posts: 55
Joined: Thu Nov 06, 2014 7:18 pm

Re: Embedding Python into your apps

Post by smacker »

Got a question...

Is "python31.dll" the only version of the .dll this will work with?
The world and human nature was screwed up before I was born. It's not my fault and I'm just stuck with trying to deal with the mess left behind, so don't blame me.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 635
Joined: Fri Dec 04, 2015 9:26 pm

Re: Embedding Python into your apps

Post by skinkairewalker »

Hi everyone !

well , i have problems in import Python DLL ,

when i call with > OpenLibrary(1,"python35.dll")

dont call library ...

follow the screenshot > http://prntscr.com/d5iquh

this is Dlls in my folder http://prntscr.com/d5ipwg

how can i fix this ?
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Embedding Python into your apps

Post by jack »

is the dll 32-bit or 64-bit?
my guess is that it's 32-bit and you need the 64-bit version since you are using PB x64, or you could use PB x86
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 635
Joined: Fri Dec 04, 2015 9:26 pm

Re: Embedding Python into your apps

Post by skinkairewalker »

now show this error > http://prntscr.com/d5n5j0

this is code used >

Code: Select all

Prototype Py_Initialize()
Prototype.s PyRun_SimpleString(String.s)
Prototype Py_Finalize()

If OpenConsole("Python with PB")
  
  If OpenLibrary(0, "python35.dll")

    PythonInitialize.Py_Initialize = GetFunction(0, "Py_Initialize")
    PythonRunSimpleString.PyRun_SimpleString = GetFunction(0, "PyRun_SimpleString")
    PythonFinalize.Py_Finalize = GetFunction(0, "Py_Finalize")
    
    PythonInitialize()
   pystring$ = "from time import time, ctime" + Chr(10)
    pystring$ = "print('Hello PB World from Python!')" + Chr(10)
    pystring$ + "print('Today is', ctime(time()))"
    
     PythonRunSimpleString(pystring$)
    
     PythonFinalize()
 
     CloseLibrary(0)
     
     Delay(3000)
    
   EndIf 
   
   CloseConsole()
  
EndIf   
Last edited by skinkairewalker on Thu Nov 10, 2016 8:03 pm, edited 1 time in total.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 635
Joined: Fri Dec 04, 2015 9:26 pm

Re: Embedding Python into your apps

Post by skinkairewalker »

i fix this error !
just need Set System Variable ,
PYTHONHOME = C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX
AND
PYTHONPATH = C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX; C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX\DLLs;
C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX\Lib;
C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX\libs;
C:\Users\YOURPC\AppData\Local\Programs\Python\PythonXX\Lib\site-packages


and this bug has fixes ...
note > Python 3.2 or greater
ccode
User
User
Posts: 99
Joined: Sat Jun 23, 2018 5:21 pm

Re: Embedding Python into your apps

Post by ccode »

Hello!

I know that the thread is already old.
How does it work under a current Linux?
How can I use this to execute entire Python scripts?
Post Reply