Start a new topic

mgapi compatibility issue

Porting things to a new PC, and my script/s are broken.  New PC is windows 10.  Trying to get standalone python working.

API files from v14.2 or thereabouts.


Here's the error after my import attempt:

System error: mgapilib not found!


Code:

try:
from mgapilib import *
except:
my_fatal_err('System error: mgapilib not found'


Presagis vars:

MPI_INSTALL_DEFAULT=C:\Presagis

PRESAGIS_CREATOR=C:\Presagis\Suite16\Creator

PRESAGIS_CREATOR_16_0=C:\Presagis\Suite16\Creator

PRESAGIS_LICENSING=C:\Presagis

PRESAGIS_OPENFLIGHT_API=C:\Presagis\OpenFlight_API

PRESAGIS_OPENFLIGHT_SCRIPT=C:\Presagis\OpenFlight_API\bin\release

PRESAGIS_ROOT=C:\Presagis

PYTHONPATH=C:\Presagis\OpenFlight_API\bin\release


From the interpreter I can see:

E:\utils>python

Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> from mgapilib import *

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "C:\Presagis\OpenFlight_API\bin\release\mgapilib.py", line 7, in <module>

    import _mgapilib

ImportError: DLL load failed: %1 is not a valid Win32 application.


Help!


Thx



Indeed, that is the problem!  Thank you very much!!


E:\>python ptest.py

I: OpenFlight API version 16.0.0.

I: Loading plugin <OpenFlight Data Dictionary> from <C:/Presagis/Suite16/OpenFlight_API/bin_x64/release/fltdata.dll>...

I: Site <FLTDATA> registered for plugin <OpenFlight Data Dictionary>.

I: Plugin <OpenFlight Data Dictionary> loaded.




Shawn, the output from your python interpreter suggests it is a 32 bit version of Python. 

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32

That will not work with a 64 bit version of the OpenFlight API. 

Either find and install a 64 bit version of Python or set 
PYTHONPATH and 
PRESAGIS_OPENFLIGHT_SCRIPT to the 32 bit folders of the OF API bin folder.

 

Shawn, the output from your python interpreter suggests it is a 32 bit version of Python.

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32

That will not work with a 64 bit version of the OpenFlight API. 

Either find and install a 64 bit version of Python or set 
PYTHONPATH and PRESAGIS_OPENFLIGHT_SCRIPT to the 32 bit folders of the OF API bin folder.


Hm.

Previously I moved my cmd window location.  That seems to no longer help.


PC has been rebooted.

Vars:

C:\Users\sallen>set | grep PYTHON

PYTHONPATH=C:\Presagis\Suite16\OpenFlight_API\bin_x64\release

 

C:\Users\sallen>set | grep OPENF

PRESAGIS_OPENFLIGHT_API=C:\Presagis\Suite16\OpenFlight_API

PRESAGIS_OPENFLIGHT_API_16_0=C:\Presagis\Suite16\OpenFlight_API

PRESAGIS_OPENFLIGHT_API_LAST=C:\Presagis\OpenFlight_API

PRESAGIS_OPENFLIGHT_SCRIPT=C:\Presagis\Suite16\OpenFlight_API\bin_x64\release

 

C:\Users\sallen>dir %PYTHONPATH%

 Volume in drive C is System

 Volume Serial Number is 96C6-CD68

 

 Directory of C:\Presagis\Suite16\OpenFlight_API\bin_x64\release

 

02/08/2018 02:11 PM <DIR> .

02/08/2018 02:11 PM <DIR> ..

12/12/2016 12:27 AM 280,576 fltdata.dll

12/12/2016 12:27 AM 2,483,712 mgapilib.dll

12/12/2016 12:32 AM 279,252 mgapilib.py

02/08/2018 02:08 PM 258,180 mgapilib.pyc

12/12/2016 12:24 AM 65,024 mgdd.dll

12/12/2016 12:23 AM 157,696 mgmemory.dll

12/12/2016 12:24 AM 738,816 mgruntime.dll

12/12/2016 12:32 AM 1,216,000 _mgapilib.pyd

               8 File(s) 5,479,256 bytes

               2 Dir(s) 273,317,257,216 bytes free


C:\WINDOWS\system32>python

Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import mgapilib

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "C:\Presagis\Suite16\OpenFlight_API\bin_x64\release\mgapilib.py", line 7, in <module>

    import _mgapilib

ImportError: DLL load failed: %1 is not a valid Win32 application.

>>>


To be clear, the python script is sitting in a folder with no other .py scripts, and as far as I know, the error I am getting is from the API install.  The folder path is clearly bin_x64 yet the error message indicates, at a guess, a syntax error within the API.


I have made no changes to the API folder locations, not even copying my script files in there.


I do get a similar error from my script:

E:\>python sa_eggetattr2.py blip.flt

Traceback (most recent call last):

  File "sa_eggetattr2.py", line 25, in <module>

    from mgapilib import *

  File "C:\Presagis\Suite16\OpenFlight_API\bin_x64\release\mgapilib.py", line 7, in <module>

    import _mgapilib

ImportError: DLL load failed: %1 is not a valid Win32 application.


And running the ptest.py script:

 

 

HTML

from mgapilib import *
mgInit(None,None)
mgExit()

 

E:\>python ptest.py

Traceback (most recent call last):

  File "ptest.py", line 1, in <module>

    from mgapilib import *

  File "C:\Presagis\Suite16\OpenFlight_API\bin_x64\release\mgapilib.py", line 7, in <module>

    import _mgapilib

ImportError: DLL load failed: %1 is not a valid Win32 application.


System path includes 

C:\Python278

C:\Python278\Scripts


This looks exactly like the original problem you had at the top of this thread. You managed to get that working, I suspect you've fallen into the same quagmire again. Review the thread to make sure you have everything set up properly.

At the end of the day, all you have to do for OpenFlight Script to work is set these two environment variables.


PYTHONPATH=C:\Presagis\Suite16\OpenFlight_API\bin_x64\release

PRESAGIS_OPENFLIGHT_SCRIPT=C:\Presagis\Suite16\OpenFlight_API\bin_x64\release


presuming you have installed OpenFlight API 16 x64 and have a 64 bit version of Python installed.


And remember after you install and reset environment variables, you MUST restart any application to pick up the new environment variables. To be safe, it's always best to:

  1. Install New OpenFlight API.
  2. Set env vars to reflect new installation.
  3. Reboot.


Good luck.


Help!  I have to resurrect this thread.


I've just uninstalled OpenFlightAPI, then  D/L & install OpenFlightAPI windows from here:

https://portal.presagis.com/support/solutions/articles/19000058654-openflight-api-16


It looks like there is some conflict between 32 and 64 bit versions (due to the error message):

  

C:\Presagis\Suite16\OpenFlight_API\samples>cd scripts



C:\Presagis\Suite16\OpenFlight_API\samples\scripts>python egnew1.py

Traceback (most recent call last):

  File "egnew1.py", line 26, in <module>

    from mgapilib import *

  File "C:\Presagis\Suite16\OpenFlight_API\bin_x64\release\mgapilib.py", line 7, in <module>

    import _mgapilib

ImportError: DLL load failed: %1 is not a valid Win32 application.

I don't see where my environment is pointing to the wrong library.  


PYTHONPATH=C:\Presagis\Suite16\OpenFlight_API\bin_x64\release


Tried the trick of moving out of the folder & re-running the script, same error.


This is Python 2.7.8.  BTW I am able to run 'standard' python scripts fine, just nothing 


Tried on a different script, it looks like python isn't finding mgapilib, but:


C:\Presagis\Suite16\OpenFlight_API\bin_x64\release>dir /b

fltdata.dll

mgapilib.dll

mgapilib.py

mgapilib.pyc

mgdd.dll

mgmemory.dll

mgruntime.dll

_mgapilib.pyd



There are no files in the current folder *mg* or *dll*.


Thx


OK.  I had to use a python script (that calls mgapilib) and it also failed, but when I shifted the .py into a different folder it ran fine.

Well we'll see when we get there. But frankly, unless you munged the OpenFlight API Python library file itself, there is very little chance this is being caused by the OpenFlight Script library file. If these messages were coming out when you called mgInit, I might guess that there is a plugin that is trying to load and spitting these messages out. Remember when you call mgInit (even in OpenFlight Script), mgInit looks around for "plugins" to load (data extensions, image importers, etc).


Keep us posted.

Steve,


It's entirely possible I have munged something.  This is a new PC, there are no mg* files in the utils folder. I ran a couple install commands but haven't got specifics.


 

e:\utils>path | grep PYTHON

e:\utils>

 


Sounds like I need to think about rebuilding my utils folder.


If this happens on another PC, then what..?

Without access to your computer I cannot begin to diagnose what is happening. Could python have found another mgapilib.py in the directory where you are running from? Could you have accidentally (or long ago and have forgotten about it) put a copy of mgapilib.py into the python installation folder? Again without looking around your computer, I have no idea how importing mgapilib can cause that crazy output. It almost looks like stuff that a plugin might be printing when it is initialized. 


Hmmm.... 


Anyway, sounds like you've figured out a workaround. I don't think this is a problem within mgapilib.py or any of the other installed OF API files. Must be something strange with your python environment.

running the import mgapi command from the interpreter also results in the output being generated, AND the interpreter is also exited.


So I moved up a directory level and tried it again (mgapi from the interpreter)

It works as expected - the command executes and back to the interpreter.


So I look for mg* files in the original folder, and nothing there:

 

E:\utils>dir mg*                                                                                                         Volume in drive E is User                                                                                               Volume Serial Number is 0878-963A                                                                                                                                                                                                               Directory of E:\utils                                                                                                                                                                                                                          File Not Found

 Shifting the test script out of the original folder also seems to work OK:

 

E:\>python ptest.py
I: OpenFlight API version 16.0.0.
I: Loading plugin <OpenFlight Data Dictionary> from <C:/Presagis/Suite16/OpenFlight_API/bin_x64/release/fltdata.dll>...
I: Site <FLTDATA> registered for plugin <OpenFlight Data Dictionary>.
I: Plugin <OpenFlight Data Dictionary> loaded.

 

What the heck??

First... of course the 2nd and 3rd calls (mgInit and mgExit) are going to fail without the first line when you invoke them all from "outside of python". To fix this "enter" the python interpreter first and then enter the three lines separately. To do that simply type "python" at the command line prompt and hit enter. When you do this you will enter the python interpreter. Then when you type commands here, they are kept together:
from mgapilib import *

mgInit(None,None)

mgExit()

it will work as you expect.


Second, it sounds like the "from mgapilib import *" command made all that crazy output. Is that correct? If so I cannot explain where that is coming from. Instead of the "from mgapilib import *" variant, can you try just "import mgapilib" and tell us if the same output is displayed?


OK, the first line (import) generates output:

 

from mgapilib import *

 Splitting off the other 2 lines have predictable results at least:


E:\utils>python ptest2.py

Traceback (most recent call last):

  File "ptest2.py", line 1, in <module>

    mgInit(None,None)

NameError: name 'mgInit' is not defined

 

E:\utils>emacs ptest3.py

 

E:\utils>python ptest3.py

Traceback (most recent call last):

  File "ptest3.py", line 1, in <module>

    mgExit()

NameError: name 'mgExit' is not defined


Ok, I think I am starting to understand. I have no idea where that output is coming from. To help isolate a bit more split your script into its component 3 lines and run each line separately. Let me know when that output is printed by python. i.e. which of the 3 lines actually triggers that output.

Thanks

re: output - please re-read my post.  The entire script is at the top :)

There is no output in the script, so I really don't know how/why it gets generated.


Thx

Login to post a comment