I’d like for my plugin to install a certain Python package, but I only find internal API’s that achieve this. Is there any non-internal API that could be used to check for if a certain package exists, and if not, install it?
The package provides a testing framework for the language I’m adding support for. I can’t embed the testing framework with the plugin.
This is a bit fragmented right now - PyPackageManager is deprecated, but might still be available - that’s the old thing that worked. They did add new API, but I had to abandon that because it was incomplete/part internal.
What I had to resort to was getting the user’s python interpreter, finding its path, and then running manual pip commands to check if a package is present and handle installation if needed as a subprocess.
I later abandoned python packages altogether and found a way to achieve what the python package did with bundled binaries - I get that this might not be possible for your use case, but make sure there is no such viable workaround that could work for you. Having deps bundled is easier and provides a smoother workflow.
@peppar I think we could open PythonPackageManagerUI.installPackagesWithModalProgressBlocking or PythonPackageManager.install as Experimental, but there is no guarantee that it will not be changed in 2026.2 or later.
These methods unfortunately don’t accept a version specification for the package. For this, I can revert to using PyPackageManagerUI.
However, I also need a way to determine whether the package is currently installed so that I can disable the button when it isn’t needed. What would be the ideal way to do that?
PyPackageManager used to support that, but it is now marked “deprecated, for removal”.
Huge thanks, with that help I was able to make my plugins compatible with PyCharm 261.
Edit: got it working so the following I don’t need anymore.
However, I also support Idea, and verification fails for PythonPackage.getName() and .getVersion()
PythonPackage is @Internal on idea/261.22158.277, but public on PyCharm 261.22158.220
Do you think it was possible to remove the annotation in Idea, too?