It appears you cannot just import ctypes.windll, you need to import ctypes and then use ctypes.windll. I discovered that by printing all properties of ctypes:

import ctypes
print dir(ctypes)

What's also interesting is that IPython autocompletion was misleading here, because it didn't show windll as a possible choice when TAB-autocompleting after import ctypes..

Answer from gaborous on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › having an error with ctypes
r/learnpython on Reddit: Having An Error With CTypes
April 28, 2023 -

Trying to take values from a arduino joystick, put it into serial monitor, read it with python and output that as key presses. Sorry for the long winded explanation. When I run it, the pydirectinput has an error called

ctypes' has no attribute 'windll

I know where it is and that it is because I am on Mac, but what do I replace it with?????

Thanks in advance.

Top answer
1 of 3
1
import serial import pydirectinput arduino = serial.Serial('/dev/cu.usbmodem14201', 115200, timeout=.1) #serial input from arduino. change COM port to wherever your arduino is connected pydirectinput.PAUSE = 0 keysDown = {} #list of currently pressed keys def keyDown(key): #what to do if key pressed. takes value from handleJoyStickAsArrowKeys keysDown[key] = True #adds key to KeysDown list pydirectinput.keyDown(key) #runs pydirectinput using key from (argument) #print('Down: ', key) #remove '#' from print to test data stream def keyUp(key): #what to do if key released. takes value from handleJoyStickAsArrowKeys if key in keysDown: del (keysDown[key]) #remove key from KeysDown pydirectinput.keyUp(key) #runs pydirectinput using key from (argument) #print('Up: ', key) #remove '#' from print to test data stream def handleJoyStickAsArrowKeys(x, y, z): #note that the x and y directions are swapped due to the way I orient my thumbstick if x == 0: #0 is up on joystick keyDown('up') #add up key to keyDown (argument) keyUp('down') #add down key to keyUp (argument), as you can't press up and down together elif x == 2: #2 is down on joystick keyDown('down') keyUp('up') else: #1 is neutral on joystick keyUp('up') keyUp('down') if y == 2: #2 is right on joystick keyDown('right') keyUp('left') elif y == 0: #0 is left on joystick keyDown('left') keyUp('right') else: #1 is neutral on joystick keyUp('left') keyUp('right') if z == 1: #z argument is JSButton in this case. 1 is button pressed keyDown('i') #key to be pressed with Joystick button. Change to any key else: keyUp('i') #0 is button not pressed while True: rawdata = arduino.readline() #read serial data from arduino one line at a time data = str(rawdata.decode('utf-8')) #decode the raw byte data into UTF-8 if data.startswith("S"): #make sure the read starts in the correct place dx = int(data[1]) #X direction is second digit in data (data[0] is 'S') dy = int(data[3]) #Y direction is fourth digit in data JSButton = int(data[5]) #JSButton is sixth digit in data #print(dx, dy, JSButton) #remove '#' from print to test data stream handleJoyStickAsArrowKeys(dx, dy, JSButton) #run body of code using dx, dy and JSButton as inputs It is properly indented
2 of 3
1
Traceback (most recent call last): File "/Users/User/Desktop/Joystick/Joystick5.py", line 2, in import pydirectinput File "/Users/user/.pyenv/versions/3.11.3/lib/python3.11/site-packages/pydirectinput/init.py", line 6, in SendInput = ctypes.windll.user32.SendInput ^ AttributeError: module 'ctypes' has no attribute 'windll'
Discussions

[Bug in Experimental] Cannot import windll on Linux
Greeting, as the name suggests, I get the following error when trying to start in experimental branch: ImportError: cannot import name 'windll' from 'ctypes' (/usr/lib/python3.10/ct... More on github.com
🌐 github.com
1
August 15, 2024
ImportError: cannot import name WINFUNCTYPE
Hi all, I am new to Ignition Perspective and I am using a 8.1.1 version. I am trying to extract information from a windows file and convert it into the ASCII but when I am running the code I am repeatedly having this error. Please give your inputs for below code: from ctypes import POINTER, ... More on forum.inductiveautomation.com
🌐 forum.inductiveautomation.com
3
0
July 26, 2021
cannot import name 'WinDLL' from 'ctypes' (/usr/lib/python3.9/ctypes/__init__.py)
This is autogenerated. Please review and update as needed. Describe the bug Command Name az network bastion rdp Extension Name: bastion. Version: 0.2.3. Errors: Paste here the error message you hav... More on github.com
🌐 github.com
4
March 20, 2023
'az network bastion tunnel' crashes with "cannot import name 'WinDLL' on MacOS
Describe the bug When trying to connect to VM through bastion with Microsoft Remote Desktop on MacOS, It errors to WinDLL can't be loaded so RDP connection does not work. Issue #26298 seems to ... More on github.com
🌐 github.com
5
May 31, 2023
🌐
GitHub
github.com › Azure › azure-cli › issues › 23143
`az network bastion rdp` fails: ImportError: cannot import name 'WinDLL' from 'ctypes' · Issue #23143 · Azure/azure-cli
July 7, 2022 - Here is the traceback: cannot import name 'WinDLL' from 'ctypes' (/opt/az/lib/python3.10/ctypes/__init__.py) Traceback (most recent call last): File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 231, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute raise ex File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/az/lib/python3.10/site-packages/azure/cli/core
Author: Azure
🌐
GitHub
github.com › hacksider › Deep-Live-Cam › issues › 348
[Bug in Experimental] Cannot import windll on Linux · Issue #348 · hacksider/Deep-Live-Cam
August 15, 2024 - Greeting, as the name suggests, I get the following error when trying to start in experimental branch: ImportError: cannot import name 'windll' from 'ctypes' (/usr/lib/python3.10/ctypes/__init__.py) I suspect that either windll cannot be...
Author: hacksider
🌐
Inductive Automation
forum.inductiveautomation.com › ignition
ImportError: cannot import name WINFUNCTYPE - Ignition - Inductive Automation Forum
July 26, 2021 - Hi all, I am new to Ignition Perspective and I am using a 8.1.1 version. I am trying to extract information from a windows file and convert it into the ASCII but when I am running the code I am repeatedly having this error. Please give your inputs for below code: from ctypes import POINTER, WINFUNCTYPE, c_char_p, c_void_p, c_int, c_ulong, c_char_p from ctypes.wintypes import BOOL, DWORD, BYTE, INT, LPCWSTR, UINT, LONG, ULONG, LPCSTR, PCHAR, PWCHAR import ctypes from ctypes import byref imp...
🌐
Medium
christophjones.medium.com › adding-a-pandas-layer-to-aws-lambda-38520872bd3d
Adding a Pandas Layer to AWS Lambda | by Chris Jones | Medium
December 4, 2020 - “numpy: cannot import name ‘WinDLL’ from ‘ctypes’ (/var/lang/lib/python3.7/ctypes/__init__.py)”.
🌐
Narkive
wingide-users.wingware.narkive.com › grFeBjj3 › ctypes-on-windows-windll-is-not-defined
[wingide-users] ctypes on windows - windll is not defined
""" from ctypes import * print windll.kerel32 """ Easy as that is: in the interpreter it works perfectly, returning <WinDLL 'kernel32', handle 7c8 blablabla> However - using the debugger and running the script directly doesn't work. Any time I import ctypes that works without any hassle, but I get: "NameError: name 'windll' is not defined."
🌐
GitHub
github.com › Azure › azure-cli-extensions › issues › 6042
cannot import name 'WinDLL' from 'ctypes' (/usr/lib/python3.9/ctypes/__init__.py) · Issue #6042 · Azure/azure-cli-extensions
March 20, 2023 - Here is the traceback: cannot import name 'WinDLL' from 'ctypes' (/usr/lib/python3.9/ctypes/init.py) Traceback (most recent call last): File "/usr/lib64/az/lib/python3.9/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/core/commands/init.py", line 726, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/usr/lib64/az/lib/python3.9/site-packages/azure/cli/
Author: Azure
Find elsewhere
🌐
GitHub
github.com › Azure › azure-cli-extensions › issues › 6350
'az network bastion tunnel' crashes with "cannot import name 'WinDLL' on MacOS · Issue #6350 · Azure/azure-cli-extensions
May 31, 2023 - Here is the traceback: cli.azure.cli.core.azclierror: cannot import name 'WinDLL' from 'ctypes' (/opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/init.py) Traceback (most recent call last): File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/init.py", line 663, in execute raise ex File "/opt/homebrew/Cellar/azure-cli/2.47.0/libexe
Author: Azure
🌐
OneCompiler
onecompiler.com › python › 3z28pvfe6
Python Online Compiler & Interpreter
March 11, 2023 - OneCompiler's Python online editor helps you to write, interpret, run and debug python code online. Libraries for data science and machine learning are also available
🌐
Python Forum
python-forum.io › thread-25936.html
possible ctypes and numpy conflict?
Greetings, i wonder if anyone could help me to solve the following problem with python and following libraries: numpy, cv2, ctypes, pywin32 as they seem to conflict. The stroy goes as follows: i always had cv2 with numpy on my machine in a system wi...
🌐
GitHub
github.com › Azure › azure-cli › issues › 23228
az network bastion rdp error following docs · Issue #23228 · Azure/azure-cli
July 18, 2022 - This is autogenerated. Please review and update as needed. Describe the bug Command Name az network bastion rdp Errors: The command failed with an unexpected error. Here is the traceback: cannot import name 'WinDLL' from 'ctypes' (/opt/a...
Author: Azure
🌐
Python
docs.python.org › 3 › library › ctypes.html
ctypes — A foreign function library for Python
ctypes exports the cdll, and on Windows windll and oledll objects, for loading dynamic link libraries.
🌐
GitHub
github.com › colinoflynn › pico-python › issues › 80
ImportError: cannot import name windll on Macos X · Issue #80 · colinoflynn/pico-python
July 7, 2017 - In [3]: ps = ps2000.PS2000() --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-3-3eb67f4a7698> in <module>() ----> 1 ps = ps2000.PS2000() /usr/local/lib/python2.7/site-packages/picoscope/ps2000.pyc in __init__(self, serialNumber, connect) 128 self.lib = cdll.LoadLibrary("lib" + self.LIBNAME + ".so") 129 else: --> 130 from ctypes import windll 131 self.lib = windll.LoadLibrary(self.LIBNAME + ".dll") 132 ImportError: cannot import name windll ·
Author: colinoflynn
Top answer
1 of 2
5

Aws lambda will throw you an error if you don't have the correct version of dependencies packaged with your code, which may depend on the OS (lambda runs on linux) and the python version.

Based on your requirements, it's pandas throwing you the error. To run pandas on lambda, you need to include the following packages:

pandas - code compiled for the linux, which is what lambda runs you. You can find it here https://pypi.org/project/pandas/#files download the 'manylinux' version of the .whl file, that matches your python lambda version.

  • e.g. if you are running py3.7, then get pandas-0.25.3-cp37-cp37m-manylinux1_x86_64.whl

  • Unzip the contents of the .whl file into the root folder of your lambda folder. This is the library version that lambda needs

  • Note for pandas 0.25+, you also need to include the pytz package as well, see note below on requests

numpy - You can now get in lambda (tested for py3.7) through installing a 'layer' through the lambda console, see screenshots below.

  • Doesn't seem there's a layer for py3.8 yet so you'll need to do download the correct .whl file from pypi, just like pandas https://pypi.org/project/numpy/#files

Side note on requests

  • Notice that the package here https://pypi.org/project/requests/#files only have a 'none-any' version, that means the source doesn't need to be compiled, so you can safely include the version you got from pip

  • this applies to the pytz dependency of pandas as well

Screenshots installing layers in aws console

2 of 2
2

Since numpy is written in C you should build it for a linux distribution. I recommend you using the serverless framework because it will simplify your life a lot when you are using a Windows laptop.

Install the serverless framework and make sure you have docker

go to the root of your project and execute:

sls create --template aws-python

install the plugin for deploying python apps:

serverless plugin install -n serverless-python-requirements

in your serverless.yml file add:

plugins:
   - serverless-python-requirements

custom:
  pythonRequirements:
     dockerizePip: non-linux

make sure you adjust the path to your lambda function

functions:
  hello:
    handler: handler.hello

deploy with the correct libraries using

sls deploy 
🌐
GitHub
github.com › zai-org › ChatGLM-6B › issues › 1487
python3 cli_demo.py · Issue #1487 · zai-org/ChatGLM-6B
July 8, 2024 - [root@VM-0-7-centos ChatGLM-6B-main]# python3 cli_demo.py Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/pyreadline3/keysyms/init.py", line 15, in from .keysyms import * File "/usr/local/lib/python3.10/site-packages/pyreadline3/keysyms/keysyms.py", line 13, in from ctypes import windll ImportError: cannot import name 'windll' from 'ctypes' (/usr/local/lib/python3.10/ctypes/init.py)
Author: zai-org
🌐
GitHub
github.com › Azure › azure-cli › issues › 31296
cannot import name 'WinDLL' from 'ctypes' on macOS · Issue #31296 · Azure/azure-cli
April 18, 2025 - Here is the traceback: cli.azure.cli.core.azclierror: cannot import name 'WinDLL' from 'ctypes' (/opt/homebrew/Cellar/python@3.12/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/init.py) Traceback (most recent call last): File "/opt/homebrew/Cellar/azure-cli/2.71.0/libexec/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke cmd_result = self.invocation.execute(args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Cellar/azure-cli/2.71.0/libexec/lib/python3.12/site-packages/azure/cli/core/commands/init.py", line 666, in execute raise ex File "/opt/homebrew/
Author: Azure