freelanceprogrammers.org Forum Index » Delphi
Set Python import path sys.path to exact value early?
Joined: 21 Dec 2006
Posts: 8
Set Python import path sys.path to exact value early?
OnPathInitialization didn`t do what I expected.
the sys.path obviously arises from the Registry on Win and only if not
existing, then OnPathInitialization - if present - will even set the
registry value!
I just want to set sys.path very very early in the game (at least
before any non-builtin modules are imported. And not set/change any
python registry settings (for deployment and testing).
What is the best technique?
Robert
(v3.25, py23)
Joined: 29 Apr 2005
Posts: 103
Set Python import path sys.path to exact value early?
Look at the deploying P4D PDF document that explains all these tricks
(there is a link in the Python For Delphi start menu).
Morgan
--- In pythonfordelphi@yahoogroups.com, "kxroberto" <kxroberto@...> wrote:
>
> OnPathInitialization didn`t do what I expected.
>
> the sys.path obviously arises from the Registry on Win and only if not
> existing, then OnPathInitialization - if present - will even set the
> registry value!
>
> I just want to set sys.path very very early in the game (at least
> before any non-builtin modules are imported. And not set/change any
> python registry settings (for deployment and testing).
>
> What is the best technique?
>
> Robert
>
> (v3.25, py23)
>
Joined: 21 Dec 2006
Posts: 8
Set Python import path sys.path to exact value early?
Morgan Martinet wrote:
>
> Look at the deploying P4D PDF document that explains all these tricks
> (there is a link in the Python For Delphi start menu).
>
----------
Had read that. It just tells that thing with OnPathInitialization etc,
which does not overdrive existing Python paths on a installation having
already Python.
I found so far, that something simple like
VarPyth.SysModule.path.append(ExtractFilePath(Application.ExeName));
// for DLLs
VarPyth.SysModule.path.insert(0,ExtractFilePath(Application.ExeName)+`pystuff.zi
p`)
// for .pyo`s ..
.. at the very beginning before using any python does it (at least for
py23 - and in addition to OnPathinit)
It only draws os.pyc from a possibly existing python installation :-(
everything else is from pystuff.zip :-) (though pystuff.zip has also
os.pyo )
Robert
Joined: 29 Apr 2005
Posts: 103
Set Python import path sys.path to exact value early?
Did you try to put python2x.dll in the same folder as your
application? In that case, it should be picked by the LoadDll (or you
can also set the DllPath property) and it will ensure that the correct
version of Python is initialized with the proper modules if you copy
them along with the dll.
--- In pythonfordelphi@yahoogroups.com, Robert <kxroberto@...> wrote:
>
> Morgan Martinet wrote:
> >
> > Look at the deploying P4D PDF document that explains all these tricks
> > (there is a link in the Python For Delphi start menu).
> >
>
>
>
>
>
>
>
> ----------
>
> Had read that. It just tells that thing with OnPathInitialization etc,
> which does not overdrive existing Python paths on a installation having
> already Python.
>
> I found so far, that something simple like
>
> VarPyth.SysModule.path.append(ExtractFilePath(Application.ExeName));
> // for DLLs
>
VarPyth.SysModule.path.insert(0,ExtractFilePath(Application.ExeName)+`pystuff.zi
p`)
> // for .pyo`s ..
>
>
> .. at the very beginning before using any python does it (at least
for
> py23 - and in addition to OnPathinit)
>
> It only draws os.pyc from a possibly existing python installation :-(
> everything else is from pystuff.zip :-) (though pystuff.zip has also
> os.pyo )
>
>
> Robert
>
Joined: 21 Dec 2006
Posts: 8
Set Python import path sys.path to exact value early?
--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@...>
wrote:
>
> Did you try to put python2x.dll in the same folder as your
> application? In that case, it should be picked by the LoadDll (or you
> can also set the DllPath property) and it will ensure that the correct
> version of Python is initialized with the proper modules if you copy
> them along with the dll.
Of course, I`ve a lot more dll`s and pyd to deplay also next to the
.exe. Its not about the python dll - its but about the sys.path.
As said, the reset of VarPyth.SysModule.path:=... (i do .__delslice__
and append`s) solves most, but not for os.pyc
On a machine with python already installed it though autopicks the
python23.dll next to the delphiapp.exe ( test: I cannot delete the
python23.dll when app is running ).
but checking the modul paths from inside the app I get:
>>> import sys,os,re;print sys.path,os,re
output:
[`..mypath\`, `..mypath\pystuff.zip`]
<module `os` from `C:PYTHON23Libos.pyc`>
<module `re` from `....mypathpystuff.zip e.pyc`>
So os.pyc somehow is drawn in too early before
VarPyth.SysModule.path:=.. applies. But its too much effort to figure
this out and hope nobody will "patch" his os.py in an existing
py-installation ... :-)
If no py ist already installed on a machine the
....mypathpystuff.zipos.pyc will be taken correctly ( but registry
is altered illegally to my opinion :-( )
In PythonEngine there is this piece of code:
.....
FOnPathInitialization( Self, path );
if path <> `` then
begin
//Access := KEY_ALL_ACCESS; // works only with
Delphi5 or greater
OpenKey( key, True );
WriteString( ``, path );
CloseKey;
end;
end;
! Thats a "virus" to my opinion. But maybe there is no other
possibility ..
Robert
> --- In pythonfordelphi@yahoogroups.com, Robert <kxroberto@> wrote:
> >
> > Morgan Martinet wrote:
> > >
> > > Look at the deploying P4D PDF document that explains all these
tricks
> > > (there is a link in the Python For Delphi start menu).
> > >
> >
> > ----------
> >
> > Had read that. It just tells that thing with OnPathInitialization
etc,
> > which does not overdrive existing Python paths on a installation
having
> > already Python.
> >
> > I found so far, that something simple like
> >
> >
VarPyth.SysModule.path.append(ExtractFilePath(Application.ExeName));
> > // for DLLs
> >
>
VarPyth.SysModule.path.insert(0,ExtractFilePath(Application.ExeName)+`pystuff.zi
p`)
>
> > // for .pyo`s ..
> >
> >
> > .. at the very beginning before using any python does it (at least
> for
> > py23 - and in addition to OnPathinit)
> >
> > It only draws os.pyc from a possibly existing python installation
:-(
> > everything else is from pystuff.zip :-) (though pystuff.zip has
also
> > os.pyo )
> >
> >
> > Robert
> >
>
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







