Jump to content
Geochemist's Workbench Support Forum

Using the Python Plugin


Recommended Posts

I am trying to use the GWB python plugin to batch run some different models in React.  I am running python through a Jupyter notebook, and am following the instructions for using the plugin here. The first three lines of my code are:

Quote

import sys
sys.path.append('c:/Program Files (x86)/Gwb/src')
from GWBplugin import *

which append the GWB src folder to my path successfully. However, in the next two lines of my code:

Quote

 

myPlugin = GWBplugin()

myPlugin.initialize('react')

 

I get the following error message:

Quote

 

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-32-9a5cab2537cc> in <module>
      1 myPlugin = GWBplugin()
----> 2 myPlugin.initialize('react')

<ipython-input-30-287454ca2732> in initialize(self, app_name, file_name, cmds)
      9 
     10    def initialize (self,app_name,file_name=None,cmds=None):
---> 11       return cdll.gwbplugin.c_initialize(byref(self.plugin), c_char_p(app_name), c_char_p(file_name), c_char_p(cmds))
     12 
     13    def exec_cmd (self,uline):

~\anaconda3\lib\ctypes\__init__.py in __getattr__(self, name)
    449         if name[0] == '_':
    450             raise AttributeError(name)
--> 451         dll = self._dlltype(name)
    452         setattr(self, name, dll)
    453         return dll

~\anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    379 
    380         if handle is None:
--> 381             self._handle = _dlopen(self._name, mode)
    382         else:
    383             self._handle = handle

FileNotFoundError: Could not find module 'gwbplugin' (or one of its dependencies). Try using the full path with constructor syntax.

 

I am not sure why I'm getting this error since I have already set my path to the GWB src folder. Any help would be appreciated!
 

Link to comment
Share on other sites

Hello Christine,

Can you double check that the path was added correctly to your PYTHONPATH environment variables? You should be able to navigate to it from your computer's Control Panel. 

If the path was added correctly, it would help us troubleshoot if you can provide the version of python you're using and the platform that it was built for -32bit or 64bit. I see that you're appending the path to the x86 folder, which means that you have the 32-bit version of the GWB installed. If you are using a 32-bit version of the GWB, you should also be using a 32bit version of python as well. 

Best regards,
Jia Wang
Aqueous Solutions LLC

Link to comment
Share on other sites

Hi Jia,

Thanks for the response. I am looking at my environment variables via system properties on windows and don't see anything called "PYTHONPATH".

I should say, I'm actually a Mac user running GWB on a Windows 7, 64 bit OS emulator, so I am not as well-versed in setting paths, etc on Windows. I am using the Anaconda python distribution with python version 3.8.8. I installed the 64-bit version because that was recommended for the 64 bit Windows OS.

So it seems there may be a few problems here. Where should I start?

 

 

Link to comment
Share on other sites

Hello Christine,

Thanks for the additional information. I think a good place to start is to check whether your GWB installation is 64-bit or 32-bit. Since you are using a 64-bit version of Python, you would want to do the same for GWB. To check, launch any GWB app and go to "Help" -> About App and a pop up should present the information needed. If you have the 32-bit version installed, you should be able to rerun the GWB installer and select the 64-bit version in the first step. When you have the 64-bit version installed, try appending the 'src' folder of the GWB installation to sys.path in Python again. Double check the location of your src folder and make sure the path is correct. The path in your original post indicate that the src folder is in Program files (x86), which is where 32-bit applications automatically install in Windows. For more information and example on this, please refer to the Python subsection in the Plug-in Feature of the GWB Reference Manual. 

Hope this helps,
Jia 

Link to comment
Share on other sites

Hi again Jia,

My GWB was indeed the 32-bit. I have since uninstalled it, and reinstalled the 64-bit version, however I am still getting the same error. I am using sys.path.append('C:\Program Files\Gwb\src') this time (and when I tell python to print everything in sys.path, it does indeed include that folder), but I still get the same "FileNotFoundError" as above when I try to call the initialize function. 

Link to comment
Share on other sites

Hello Christine,

Our technical team has looked into this a bit further and the error is likely due to the changes in newer versions of Python (3.8 and later). To have Python search for the dll properly a couple of additional lines of code are needed and I have provided it for your below.

Try replacing

import sys
sys.path.append('c:/Program Files (x86)/Gwb/src')
from GWBplugin import *

with

import sys
sys.path.append('c:\program files\gwb\src')
import os
os.add_dll_directory('c:\program files\gwb')
from GWBplugin import *

Please let us know if this resolved the issue for you.

Best,
Jia 

Link to comment
Share on other sites

Hello Christine, 

I am sorry to hear that didn't work. We looked into this further and it looks like the issue is with this Anaconda Python distribution. Here is a discussion forum regarding dll paths not working properly in Anaconda: https://github.com/ContinuumIO/anaconda-issues/issues/12475. Unfortunately, the fix mentioned in the discussion thread did not solve the issue in our testing.

Here are a couple of suggestions:

1. Try an installation of python from python.org and use the Plug-in feature with that instead. If this works, you can contact Anaconda's support to see what is available for fixing it or if their next update comes out will a fix for it. Our testing shows the solution in my above post works with normal python.

2. Try downgrading to an earlier version of Anaconda (3.7.x or before). 

Best regards,
Jia 

Link to comment
Share on other sites

Hi Jia,

I've finally got this working with anaconda, and figured I'd share in case anyone else wants to try this and searches through these forums for help.

I uninstalled Anaconda, downloaded Python 3.8 directly from python.org and tried running the plugin (using the exact same code as above, with the DLL fix) via the command line as you suggested, but was getting the same error message (this time it just said 'the specified module could not be found'). I tested some earlier versions of Python as well (3.6 and 3.7), and got ' "errorMessage": "module 'os' has no attribute 'add_dll_directory'"' - I guess this was only added in Python 3.8, and without the add_dll_directory line I still got the "module not found" message. 

The fix is to edit the system environment variables on Windows (Control Panel -> System-> Advanced System Settings-> Environment Variables). Under user variables, change the "PATH" variable to C:\Program Files\Gwb (not "PYTHONPATH", which should still be C:\Program Files\Gwb\src"). This did the trick, and now the plugin successfully runs both directly in a python terminal, and in my Jupyter notebook. The "add_dll_directory'" step is no longer necessary, either.

I am guessing since this was not the fix in your testing, it has something to do with how Python interacts with my emulator version of Windows 7. But in any case, I wouldn't have figured this out without going through these others steps you suggested first, so thank you very much for the help!

Link to comment
Share on other sites

  • 1 year later...

Hi Christine,

I know this is an old thread, but I just wanted to say that I was having a similar issue and this worked for me. I'm using native 64-bit Windows 10 with Anaconda on Python 3.10.6. The difference for me is that the "add_dll_directory" step is still necessary if I try to run it from a terminal. My guess is this isn't an issue with you using a VM version of Windows 7, rather the plugin needs to be updated to work on newer versions of Python. In the meantime, I think they should updated the webpage to point to this forum post, because it took me a bit to find a fix.

Thank you for posting your solution!

 

Best,

Adam

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...