PythonPip¶
-
MacroModule
¶ author MeVis Medical Solutions AG
package MeVisLab/Standard
definition PythonPip.def
Purpose¶
Introduction¶
The PythonPip
module allows to work with the Python package manager pip. It can be used to install Python packages into the site-packages of the MeVisLab Python installation.
It provides the full Python package eco-system to MeVisLab, but it has several drawbacks!
- On macOS:
- you can only install Python-only packages (packages that contain Python C-Extensions are not supported)
- On Windows and Linux:
- packages can contain C-Extensions (since we use the same MSVC compiler resp. same GCC settings as Python 3 itself)
- but you can only install packages that do not interfere with packages or DLLs that are already part of MeVisLab
- this means that installing packages with C-Extensions might work in many circumstances, but is not guaranteed to work
- all installed packages with C-Extensions are release only, so you can only import them in a release MeVisLab
Since the PythonPip module is running in Python itself, make sure that you started a fresh MeVisLab when you want to upgrade an existing package (like NumPy), since it can not be upgraded if already loaded by MeVisLab’s Python.
We tested the following packages on Windows with success (without using the frameworks deeply):
- SciPy
- SciPy with an upgraded NumPy (pip install –upgrade –force-reinstall scipy)
- SimpleITK
- Psycopg
Packages that you should not upgrade or install (because they interfere with DLLs in MeVisLab):
- vtk
- cv2 (OpenCV)
- PySide2 / PyQt (we have our own PythonQt binding and our own Qt DLLs)
- matplotlib (we have our own patched version to support PythonQt)
- probably other packages that we have not thought about
Instead of using the PythonPip module, you can also run “MeVisPython” on a commandline using:
MeVisPython -m pip ...
where MeVisPython is located in the MeVis/ThirdParty package. But note that this will always install/upgrade Python packages into MeVis/ThirdParty, which may cause problems.
Proxies¶
If you are behind a proxy, you may have to set the HTTP_PROXY and HTTPS_PROXY environment variables to the hostname and port of your proxy. These are used by pip when accessing the internet.
Deployment¶
For Windows and Linux, if you want to deploy a pip-installed Python package, you need to manually configure your installer to pick-up the package (do this at the end of your mlinstall file):
SWITCH_PACKAGE MeVis/ThirdParty
+ $(PYTHON_SITE_PACKAGES_PATH)/NameOfInstalledPackage
For macOS, you may embed additional python packages by adding the following lines to your mlinstall file:
>>EXECUTE $(OUTPUT_PYTHON_EXE) -I -m pip install --upgrade setuptools
>>EXECUTE $(OUTPUT_PYTHON_EXE) -I -m pip install <packages>
SWITCH_PACKAGE MeVis/ThirdParty
+ ThirdPartyInformation/pip
+ $(PYTHON_SITE_PACKAGES_PATH)/pip
Please note that it is up to you to correctly fulfill the requirements of the license of each Python package that you deploy, like mentioning the package usage in the documentation.
Details¶
Python packages can be installed in any MeVisLab package. The MeVis/ThirdParty package has a special role, since it represents the Python base system. We do not recommend to install Python packages there, since this might upgrade an existing package, which might interfere with other packages and can’t be reverted to the original (possibly patched) version without re-installing the MeVisLab SDK. Also the package might be write protected anyway.
Instead it is recommended to install Python packages into a user MeVisLab package that does not belong to the SDK. This way an existing package might still be installed again in a newer version if required through a dependency, but the MeVisLab package can be easily deactivated if this causes problems with other Python code.
We recommend to install Python packages only into one MeVisLab user package and perhaps switch between different MeVisLab packages if required by different projects. The tool pip only ever considers the main package repository in MeVis/ThirdParty and the target package when looking for dependencies, and might install duplicates or even conflicting versions.
The precedence of Python packages in MeVisLab packages is such that any MeVisLab package takes precendence over MeVis/ThirdParty (and MeVisLab packages added via the preferences dialog take precedence over MeVisLab packages added via the preferences file), but the precedence among the other MeVisLab packages is not defined!
In case of duplicate Python packages we also recommend to check if created application installers contain the correct version of a Python package from the correct MeVisLab package.
Parameter Fields¶
Field Index¶
allMeVisLabPackages : String |
Upgrade : Bool |
Command: pip : String |
|
Command: pip install : String |
|
Force Reinstall : Bool |
|
installPackage : Trigger |
|
runCommand : Trigger |
|
Target Package : String |
|
targetPackageWritable : Bool |
Visible Fields¶
Command: pip install¶
-
name:
package
, type:
String
¶ Installs the given python package when the install button is pressed.
Upgrade¶
-
name:
upgrade
, type:
Bool
, default:
FALSE
¶ Selects if an already installed package should be upgraded to the latest version.
Force Reinstall¶
-
name:
forceReinstall
, type:
Bool
, default:
FALSE
¶ Enables re-installation of all dependencies to the newest/required versions when upgrading.
Command: pip¶
-
name:
command
, type:
String
, default:
help
¶ Runs the given command as arguments to pip.
Target Package¶
-
name:
targetPackage
, type:
String
, default:
MeVis/ThirdParty
¶ The MeVisLab package to install the Python package into.
MeVis/ThirdParty contains the main Python repository. It is not recommended to install into any of the packages belonging to the SDK, instead create a user package and install to that. Also see the Details section.