Error in loading a Pypi package which work perfectly outside Rhino

I have develop a python package for StruSoft which work perfectly in a pure windows environment/jupyterlab.

When I try to run the following through a specific grasshopper component, something is not working correctly. Anyone is able to help? Maybe @scottd or @eirannejad ?

Our users are really willing to use our Python package through Grasshopper :slight_smile:

#! python3
#r: pywin32==306
#r: pywin32-ctypes==0.2.3
#r: FEM-Design

import win32file
from femdesign.comunication import FemDesignConnection, Verbosity
from femdesign.calculate.command import DesignModule
from femdesign.calculate.analysis import Analysis, Design, CombSettings, CombItem

I receive the following error message.
DLL load failed while importing win32file: The specified procedure could not be found.

Based on a quick research on google, it might be because of some internal environment created by rhino.

Can someone help?

Don’t assume that just because code runs perfectly in one cherry-picked environment, that it will run perfectly in all other environments too. Even pure Python code.

This dependency is causing the porblem. I’m surprised if PyWin32’s been designed to provide direct access to the Windows API, via a CPython implementation running in .Net via Pythonnet.

What does FEM-Design actually need the Windows API for? Interacting with .Net and Windows directly instead, is ideal for IronPython (but you’ll have to build your own bootstrap components to import FEM-Design).

I even see that it’s largely C# code. Why not just run it in a C# component?

We do have a c# library which works well and we also provide a grasshopper plug-in. However, we want to help the users who want to get into the API through the Python language to perform quick scripts.

I apreciate your comment, but I do not see any help in finding a solution. :slight_smile:

I do not see any help in finding a solution.

Sure. That’s because I don’t think there is a solution that will fit within a reaonably sized post, without carrying out an entire refactor, and preferably a redesign.

The current design is been based on a false assumption: that PyWin32 will work perfectly in a Grasshopper CPython component, just because it runs in a normal desktop CPython run time.

You’re trying to run PyWin32code in a different environment to the environment it was designed to be run in, and the environments it’s supported for, and tested in. PyWin32 doesn’t even support the binaries for version 306, which you’ve pinned to

So I ask again, what do you need PyWin32 for?

This is currently working for example and I believe is still part of pywin32 package

import win32pipe

FEM-Design python package requires win32file to comunicate with a win32pipe.

You can see the code in our repository.

import win32pipe

Interesting. If you only need win32file for file IO, it’s very easy to use Pthon’s native features instead for file IO.

Thankyou, I’d already looked at the source code.

What’s stopping you from adding a different interface to fd3dstruct.exe, that doesn’t require client applications to use bug prone, Windows-only operating system features, to interact with it? A simple local REST API might help you move towards runnning on Mac and Linux too.

The interface has been developed some times ago and we would like to stick with it. Really weird that Grasshopper can not load the module.

Anyone can help?