Alexey-T / Python-for-Lazarus

Fork of Python4Delphi for Lazarus, supports Windows/Linux/macOS/*BSD/Solaris
MIT License
127 stars 42 forks source link

Using python virtual environment #37

Closed agung-wete closed 2 years ago

agung-wete commented 3 years ago

Hi Is it possible to using python with virtual environment ? Thanks

Alexey-T commented 3 years ago

Py4Delphi has support for this. maybe use it? that code is not ported here.

Alexey-T commented 2 years ago

@pyscripter How Py4Delphi does it? (I know I didn't port all changes) ie what programmer must call and how in P4D?

pyscripter commented 2 years ago

In PythonVersions.pas look at venv detection

    if Is_venv then begin
      TPythonEngine(PythonEngine).VenvPythonExe := PythonExecutable;
      TPythonEngine(PythonEngine).SetPythonHome(DLLPath);
   end;

In PythonEngine.pas search for VenvPythonExe and how it is used.

Alexey-T commented 2 years ago

@pyscripter For ex, I made the venv on win32 like python -m venv myname. How I would use Py4D code with that new folder myname?

pyscripter commented 2 years ago

See https://github.com/pyscripter/python4delphi/wiki/FindingPython e.g.

var PythonVersion: TPythonVersion

if PythonVersionFromPath(Path, PythonVersion) then
begin
  PythonVersion.AssignTo(PythonEngine)
  PythonEngine.LoadDLL
end

PythonVersionFromPath does all the hard work for you.

Alexey-T commented 2 years ago

@agung-wete It seems Py4Lazarus already has the needed code. because PythonVersions unit is the same as in Py4Delphi. See https://github.com/Alexey-T/Python-for-Lazarus/issues/37#issuecomment-949788952 and try to use the wiki info.

pyscripter commented 2 years ago

@Alexey-T This is not correct. I don't think you have the venv stuff in PythonEngine.pas.

Correction. Excuse me I was wrong. I think everything is in place.

agung-wete commented 2 years ago

nice, thank you @Alexey-T , @pyscripter