Error when pip installing in Slicer's python console

Hi everyone,

I’m trying to pip install packages from the Python console in Slicer using the following commands:

import pip
pip.main(['install','pandas'])

This works perfectly well on macOS, but on Windows I get the following error (on both 10 and 11, on different machines and with different versions of Slicer: 4.11, 4.13 and 5.2.1):

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
--- Logging error ---
...

Does anyone else have the same problem?

Thanks in advance!

pip.main() is indeed old and deprecated within pip.

To install python packages using the python console in Slicer you should use pip_install. See the following resources below for examples and more details.

https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.pip_install

https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#install-a-python-package

2 Likes

Thanks a lot James, It solved my problem!

1 Like