I am trying to run a python script from within a docker container on windows7.
The python scripts loads a DLL library and calls some functions in it according to the (__stdcall) convention. I am using ctypes in python to call functions. The script is working fine when i run it from python but it is just giving me an error while runned from a docker container.
Loading of the library
dll = ctypes.WinDLL("c:\\weCat3D\\weCat3D\\EthernetScanner\\EthernetScanner")
Error from docker container
AttributeError: 'module' object has no attribute 'windll'
what is the wrong thing I am doing?
Use all lowercase for windll. You can also check whether ctypes directory have windll or not by using print (dir(ctypes)) on your console.
I checked, ctypes contains windll. Check at your end. If not then upgrade your version.
I am coming back to this issue to answer my question. I was trying to call a DLL library from within the docker container system which is containing a Linux image or Layer. That is why my calling convention for the DLL library (Windll) didn't work. I have got the same DLL library in .so (Linux version) and it is working now.
Related
I'm trying to run some code python code in Google colab. This code uses some custom modules I wrote, some of which were written in cython. On my local machine, I'd normally compile the cython code first before running my main python script. What is the correct way of doing this on colab, if there is one? Right now, the script throws an error when it tries to import my cython modules. Specifically, I get the error
ImportError: model/cython_library/core.so: invalid ELF header
which makes sense, since the core.so file was compiled on my local machine instead of gcloud.
I am trying to access C# DLL using PyCharm. I am able to access the same DLL using IronPython.
Now, I want to access that DLL in pycharm and develop script.
import clr
clr.AddReferenceToFileAndPath(r"C:Calculation.dll")
I am getting AttributeError: module 'clr' has no attribute 'AddReferenceToFileAndPath' Error
The issue here is that the guide you are following has a custom built, local module called clr.
The PyPi clr package is used to edit console string appearances.
In order to fix this, you will need to obtain the custom-built "clr" module provided by the author.
I followed this to set up twilio: https://www.fullstackpython.com/blog/send-sms-text-messages-python.html
The imports seem to be working when I run locally using python send_sms.py
Then, I use Apache Nifi ExecuteScript processor to execute the send_sms.py file and assume it should be same as if I am running the file locally.
It shows me the error:
error when calling the metaclass bases function() argument 1 must be code not str
When I am trying to: from twilio.rest import TwilioRestClient.
Twilio was installed at path /sendsms/lib/python2.7/site-packages, so I set the Module Directory to this path
Does anyone know what is wrong here? I am really stuck and please help.
ExecuteScript uses Jython (not Python) to execute pure Python scripts, and as such any imported packages (and their dependencies) must be pure Python modules as well. I am guessing that TwilioRestClient (or its dependencies) include a non-pure Python module (compiled C, e.g.). For these cases, Jython (and thus ExecuteScript) will not work.
An alternative is to use the ExecuteStreamCommand processor, with which you can shell out to your Python interpreter (and script).
I'm making an extension for a Windows program that hooks to COM server objects. I want to use Python to do this, and from what I understand, I can use Py2exe to create a DLL from a comtypes server.
For a test, I wrote a simple class that calls a print method exposed via RPC. I created a COM interface for that class, registered it, instantiated the COM object from another Python program, and called the print method. It works.
(I've created a repository for reference here: https://github.com/jakogut/python-inproc_server)
However, when I use Py2exe to create a DLL from my COM server, and try to register that DLL using regsvr32, a popup states:
The module "RemotePrint.dll" was loaded but the call to DllRegisterServer failed with error code 0x80040201
So far, I've tried running from an administrator command prompt, clearing the comtypes gen cache and recreating the DLL, profiling the runtime library dependencies using Dependency Walker (it froze/crashed, and gave no helpful information), and running on another machine.
Based on the fact that my code works as it should when I register it using the comtypes register function, I'm assuming this doesn't work as a DLL because of improper setup on my part, or a quirk with Py2exe and Python 3.
It seems that the problem was the Python Interpreter crashing because it couldn't import RemotePrintLib from comtypes.gen. Adding 'comtypes.gen' to the includes option for distutils worked!
One thing that helped diagnose this was win32traceutil.
I have downloaded an unix executable 'gtselect' used for analysing scientific data. This comes as part of a larger package of tools with installation instructions such that 'gtselect' can be called from the current working directory.
When I just run 'gtselect' everything works as expected.
I then use a python script 'gt_apps.py' which uses GtApp to wrap the tools as python objects
from GtApp import GtApp
filter = GtApp('gtselect')
and then use a different script 'run.py' to call gtselect as a python object and run it:
import gt_apps
gt_apps.filter.run()
When I run this, I receive the error
dyld: Library not loaded: libdataSubselector.dylib
Referenced from: path/bin/gtselect
Reason: image not found
Now, the library it is trying to load is instead found at
path/lib/libdataSubselector.dylib
I have tried setting
export DYLD_LIBRARY_PATH = path/lib/
but the same error persists.
Any advice? Thanks