-
Notifications
You must be signed in to change notification settings - Fork 11
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
Packages with an underscore in package name are never detected as installed. #23
Comments
@Peterdoo Why is that necessary? You only need to inform the correct package name. |
Here is an example for the package charset-normalizer: The import does not support dashes in names:
Replacing the dash with underscore, the import works fine. No error is reported:
So the only way to be able to import and use the package charset-normalizer in P4D is to set package name to charset_normalizer. When using the name with the dash as package name , it will not be imported. Also the folder where it is installed contains undersocre Lib\site-packages\charset_normalizer. So this seems to be the correct name for the package. However, pip converts all underscores to dashes, even though the folder where the package is installed is always created with the underscore:
The same when using dash in the package name:
When listing packages, pip displays a dash instead of an underscore:
TPyPackageManagerPip.IsInstalled() uses the following condition: FDefs.PackageName is charset_normalizer, because that is the only way, the package can be used and imported. As additional problem, I can just see that pip returns underscore for some packages like for example typing_extensions. Maybe the correct way would be to use the replacement function in the procedure TPyModuleBase.ImportModule instead of in the constructor TPyPackageManagerPip.Create.
Then we would have: For charset-normalizer: For typing_extensions: |
But that's why we have separated properties in the components. The package name is distinct from the names used in PIP or Conda packages. See an example here: procedure TPyTorch.Prepare(const AModel: TPyPackageModel);
begin
inherited;
with AModel do begin
PackageName := 'torch';
PackageManagers.Add(
TPyPackageManagerKind.pip,
TPyPackageManagerPip.Create('torch'));
//torch is available as pytorch under conda
// PackageManagers.Add(
// TPyPackageManagerType.conda,
// TPyPackageManagerConda.Create('pytorch'));
end;
end; You can set |
Thank you. That indeed solves this case. However I have two more examples where it does not work: Package name: pyannote.audio Package name: en_core_web_sm Is there a way I can give pip different names for installation and for checking in IsInstalled? |
Pip replaces underscores with dashes. So when the name of a package is for example my_package, pip will display it in the list command as my-package. IsInstalled will not find it and returns false.
I would recommend to make a small change to use dash for pip instead of underscore in PyPackage.Manager.Pip.pas:
constructor TPyPackageManagerPip.Create(const APackageName: TPyPackageName);
begin
inherited;
FDefs := TPyPackageManagerDefsPip.Create(APackageName.Replace('_', '-'));
FCmd := TPyPackageManagerCmdPip.Create(FDefs);
end;
The text was updated successfully, but these errors were encountered: