Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python doesn't install into a named directory #30

Open
peardox opened this issue Nov 4, 2022 · 8 comments
Open

Python doesn't install into a named directory #30

peardox opened this issue Nov 4, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@peardox
Copy link
Contributor

peardox commented Nov 4, 2022

Put a PythonEngine and PythonEnvironment39 on a form with a memo + button

Set PythonEnvironment to e.g. c:\temp\python (making sure you create it first)

procedure TForm3.Button1Click(Sender: TObject);
begin
  if PyEmbeddedResEnvironment391.Setup('3.9') then
    begin
      Memo1.Lines.Add('Setup returned True');
      if PyEmbeddedResEnvironment391.Activate('3.9') then
        Memo1.Lines.Add('Activate returned True')
      else
        Memo1.Lines.Add('Activate returned False');
    end
  else
      Memo1.Lines.Add('Setup returned False');
end;

Output...

BeforeSetup
AfterSetup
Setup returned True
BeforeActivate
Activate returned False

Extra output is from event handlers on install, activate and ready and the target directory is still empty after the run

If I already have a Python in the directory then it's ignored - SharedLibrary and Executable are both empty causing InternalActivate to fail

@lmbelo
Copy link
Member

lmbelo commented Nov 4, 2022

Which environment component and which property should I set?

@lmbelo lmbelo self-assigned this Nov 4, 2022
@peardox
Copy link
Contributor Author

peardox commented Nov 5, 2022

PyEmbeddedResEnvironment391.EnvironmentPath

If it's blank this (stupidly simple example) works otherwise it fails

PyTest.zip

Added some OnCreate code to the form - if the property is blank it's actually '$(ENVIRONMENT_PATH)\$(PYTHON_VER)' ???

I actually want to set it to something like System.IOUtils.TPath.GetHomePath + '\SomeDir'

@lmbelo
Copy link
Member

lmbelo commented Nov 5, 2022

Let me try it out.

@lmbelo lmbelo added the bug Something isn't working label Nov 5, 2022
@peardox
Copy link
Contributor Author

peardox commented Nov 5, 2022

The reason you'd want to set EnvironmentPath to something else is so that you can share a PythonEmbedded installation between multiple apps - something I can see being frequently desirable to save on disk space.

If you're using Torch GPU (like me) then each app would have about 2.5 GB of Python if not more - very wasteful

@lmbelo
Copy link
Member

lmbelo commented Nov 5, 2022

Think about venv: we can create different environment or share a single one. This is exactly what we want for PythonEnvironments, to work like venv.

@peardox
Copy link
Contributor Author

peardox commented Nov 5, 2022

Yep, exactly - that's why I'm so keen to get this working on everything.

A really interesting possibility is having a Delphi front end to a Linux WSL running on the same machine :) There are quite a few ML/AI libs that definitely prefer Linux (I'm sure a few demand it). NVidia's latest drivers can even virtualize your GPU into WSL - not played with this much though...

@peardox
Copy link
Contributor Author

peardox commented Nov 7, 2022

This is the problem...

//Let's first look for an existing environment
LEnvironmentPath := TPyEnvironmentPath.ResolvePath(
EnvironmentPath, PythonVersion);

TPyEnvironmentPath.ResolvePath merely checks for the existance of a path - it doesn't check whether the passed path has anything in it. More importantly if you pass it an empty directory it'll decide you've got Python in it :)

If you pass it a non-existant path then it'll create it and install Python in it.

Proper thing to do would be to at least install it in an empty dir - check if the passed path is empty or not...

class function TPyEnvironmentPath.ResolvePath(const APath,
APythonVersion: string): string;
begin
Result := APath.Replace(PYTHON_VER, APythonVersion);
Result := ResolvePath(Result);
end;

What's that replace doing? Ahh - replacing "$(PYTHON_VER)" with 3.9 - errm - string don't contain "$(PYTHON_VER)" in the first place - could check for that too...

Might be nice to actually check if the path you're checking has a valid Python - does python lib exist yet? Actually you've got a cancel thing now - could have valid lib but cancelled half way through. Maybe drop some JSON in the directory - e.g. PythonEmbedded.json with some installation stuff?

Lastly - this ain't backwards compatible with the previous version - if you already have a Python then the new version don't work as it's got completely different files in it so nothing is where is should be as far as the new one is concerned

@lmbelo
Copy link
Member

lmbelo commented Nov 28, 2022

It always checks for an existing Python installation in the desired folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants