Skip to content

Conversation

@idanmiara
Copy link
Contributor

No description provided.

@pyscripter
Copy link
Owner

I am not sure what it the problem you are trying to solve. From what I see you set the RegVersion from aDLLName in TPythonEngine.DoOpenDll(const aDllName : String) if UseLastKnownerion is False.
What is the use of that?

PyhthonEngine can be used to work with (a) a registered Python version and (b) a non registered Python version.

In (a) you need to set

  • RegVersion, DLLName and optionally UseLastKnownVersion if a version newer than RegVersion will do.

In (b) you need to :

  • Set DDLPath, RegVersion, DLLName and set UseLastKnownVersion to false.
  • Call SetPythonHome to the appropriate path or set the %PYTHONHOME% environment variable.

@pyscripter
Copy link
Owner

Also the implementation GetPythonVersionFromDLLName is platform specific (Windows). In addition there is no need for it to be a member of PythonEngine. It could be a stand-alone function (possibly inside PythonVersions), or a class function.

@idanmiara
Copy link
Contributor Author

idanmiara commented Oct 25, 2018 via email

@pyscripter
Copy link
Owner

I am considering including GetPythonVersionFromDLLName and possibly LatestPythonVersionFromPath but I still do not see the purpose of your other changes:

What is the use of changing DoOpenDLL? You say that

The problem I'm trying to solve is as follows:
UserInputDllName := '';
// allow user to input UserInputDllName if he wishes.
PyEngine.DllName := UserInputDllName;
PyEngine.UseLastKnownVersion := PyEngine.DllName='';
now I want to read PyEngine.RegVersion and I will get a wrong answer in
case the user specified the DLL name.

Why don't you call GetPythonVersionFromDLLName in your code i.e

if UserInputDLLName <> '' then
  PythonEngine.RegVersion := GetPythonVersionFromDLLName(UserInputDLLName);

Also regarding LatestPythonVersionFromPath. This actually deals with a corner case and anyway enen after using this method you still have to call SetPythonHome with a different path than the DLLPath.
The simple solution for QGIS would be to copy the dll and python exe files to the python directory,
By the way a QGIS user of PyScripter suggested the following script for running QGIS with PyScripter (which uses P4D) after copying the dll and python.exe files.

call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call qt5_env.bat
call py3_env.bat

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%
start "PyScripter" %~pd0\PyScripter.exe --PYTHON36 --pythondllpath=%OSGEO4W_ROOT%\apps\python36

@idanmiara
Copy link
Contributor Author

idanmiara commented Oct 25, 2018 via email

Idan Miara added 4 commits December 6, 2018 12:22
+ GetDllFileName = DllPath + DllName
+ CreateInstance, CreateInstanceAndLoad - creates an instance of the dll
+ MapDll (abstract virtual), CallMapDll - CallMapDll will be called in AfterLoad
+ LoadDll - now a function instead of procedure, returns validity.
+ DoOpenDll - use default dllname if empty string is passed; fix for loading dlls in subdirs (previous method would fail depending on its depended DLLs)
+ Import now accepts UnicodeStrings
+ Import2 for handling STDCall on 32bit
+ DllPath now writes via a function SetDllPath
+ DllFullFileName added a property that returns the full path of the dll

PythonEngine.pas - TPythonInterface
+ AfterLoad - split functionality between TPythonInterface.MapDll and TDynamicDll.CallMapDll
+ GetDllPath - add the special behavior for the PythonDLL (IsPythonVersionRegistered) which has nothing to do in TDynamicDll
+ MapDll - added functionality from TPythonInterface.GetDllPath; Import now accepts UnicodeString and not AnsiString
@idanmiara
Copy link
Contributor Author

Hi,
I've rebased my changes on your master.
I'm using your TDynamicDll as a base for other dlls that I use.
I pushed some additions and fixes.
Should I keep posting improvements to this library? If you are willing to accept contributions I will keep post them.

@idanmiara idanmiara changed the title Detect Python RegVersion correctly for UseLastKnownVersion=False TDynamicDLL improvements and other fixes Dec 6, 2018
@pyscripter
Copy link
Owner

The scope of the PR is becoming too wide, including different changes for different purposes. I am closing this. You are welcome to submit different PRs with narrow scope and specific purpose.

@pyscripter pyscripter closed this Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants