Intellij install Python package from Pycharm plugin
Answered
Hi JetBrains,
I'm developing Pycharm plugin that at the load checks certain installed Python packages and shows to the user install/update notification. Right now, I'm doing it by calling pip as process, but this does not cause Pycharm to re-scan the Python SDK indexes afterwards, causing my scripts still show errors about the missing packages. After the Pycharm restart it's OK, but installing without restart would be nice. Is there a way for the plugin to do it? Python Packages Tool Windows is already capable of that, but is there an interface to it that would allow any plugin to access it?
Thanks
Milo Macko
Please sign in to leave a comment.
Hi Milo!
Here are couple of methods that should help.
com.jetbrains.python.packaging.PyPackageManagerImpl#install
com.intellij.webcore.packaging.PackageManagementService#installPackage
Hi Aleksei,
thanks for the answer. However:
ad 1) How do I access the com.jetbrains.python ? That's not available in my gradle libraries. Only the com.jetbrains.pycharmPC
ad 2) com.intellij.webcore.packaging.PackageManagementService is an abstract class...
Thanks again
Milo
Hey Milo!
Are you using "PythonCore" plugin? (https://plugins.jetbrains.com/docs/intellij/pycharm.html#available-pycharm-apis)
You should then be able to call
PyPackageManager.getInstance
or
PyPackageManagers.getInstance.getManagementService
Hi Aleksei,
I have the community version Intellij IDEA 2022.1.2 Build #IC-221.5787.30
I installed the matching plugin 221.5787—221: https://plugins.jetbrains.com/plugin/631-python/versions/stable/180452
But still, I can not use the import com.jetbrains.python, it does not exist. Do I need to add something to my gradle script? I tried this:
But gradle reported: Plugin [id: 'PythonCore', version: '221.5787.30'] was not found in any of the following sources:
Thanks again for the help, I hope to get this working.
Milo