MapInfo Pro

 View Only
  • 1.  MapInfo Monday: Installing Additional Python Modules for MapInfo Pro

    Employee
    Posted 01-08-2024 00:01

    Happy #MapInfoMonday!

    Last week I was asked how you can install additional modules to be used from Python inside MapInfo Pro, specifically the requests module. The question came from @Sean Stephen.

    This is of course possible and once you know it, it's also quite easy to do. It's also one of those things I rarely do, so I tend to forget it in between the times I do it.

    1. From Windows Explorer go to the Python310 folder in your MapInfo Pro installation folder and double-click on the file prompt.bat.

    The default path to the MapInfo Pro installation folder is C:\Program Files\MapInfo\Professional.

    You need administrative permissions so it may be necessary to launch the prompt.bat as administrator. If so, right-click on the file and choose Run as Administrator. And that may not even be enough if you are logged in without enough credentials. 

    If you are using a different version of MapInfo Pro than v2023, the folder may be named differently depending on the version of Python we deploy with MapInfo Pro.

    2. If the Command Prompt doesn't start in the Python310 folder in your MapInfo Pro installation folder, use the cd command to navigate there.
    This is typically the case when you use Run As Administrator.
    3. You can now use pip to download and install additional Python modules.
    The command looks like this: python -m pip install <module name>

    where <module name> is the name of the module.

    4. The requested module will now be downloaded and installed if it is available.
    You can now take advantage of functions from the additional module from your Python code.


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------


  • 2.  RE: MapInfo Monday: Installing Additional Python Modules for MapInfo Pro

    Posted 01-08-2024 02:35

    Thank you, Peter.  This was invaluable.



    ------------------------------
    Sean Stephen
    Senior Digital Analyst
    Belfast City Council
    Belfast
    ------------------------------



  • 3.  RE: MapInfo Monday: Installing Additional Python Modules for MapInfo Pro

    Employee
    Posted 01-09-2024 10:24

    Hi Peter,

    There is an easier way to do this. There are some built in commands that help with modules:

    Try these in the Pro Python Console window:

    list_modules()
    install_module('requests')
    list_modules()
    uninstall_module('requests')
    list_modules()



    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 4.  RE: MapInfo Monday: Installing Additional Python Modules for MapInfo Pro

    Employee
    Posted 01-09-2024 10:29

    Great suggestion, Bob.

    I recall having seen the install_module command earlier.

    Of course, it will then be necessary to run MapInfo Pro with elevated rights.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------