python - 没有模块名称 Pythonwin
问题描述
我收到此错误
C:\Users\Rayner\Desktop>python try.py Traceback(最近一次调用最后):文件“try.py”,第 1 行,in from pythonwin import pywin ImportError: No module named pythonwin
运行此代码时
from pythonwin import pywin
import win64api, win64con, time
import math
def click(pos):
x, y = pos
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click((150, 1000))
## clicks on google chrome on the taskbar to get out of IDLE
r = 303 ## radius (largest that will fit)
## this is the center of the circle
x1 = 500
y1 = 390
## number of dots (minus 1)
n = 3000
time.sleep(1) ## waits for chrome window to open
theta = 0
for i in range(n): ## basic circle drawing algorithm
theta += 2*math.pi/n
x = round(math.cos(theta)*r)
y = round(math.sin(theta)*r)
click((x+x1, y+y1))
解决方案
毕竟你不需要导入 pywin。你没有使用它。而是将导入更改为以下内容,程序应该可以正常工作。
#from pythonwin import pywin
import win32api, win32con, time, math
而且你没有做任何事情来在你的程序中打开 chrome。这只会用你的指针在屏幕上画一个圆圈(你显然可以看到)。
推荐阅读
- python - 与多个 numpy 数组的矩阵乘法
- javascript - 我想使用 jquery 为每行中的不同分数分配等级
- swift - 不调用在协议扩展中添加的函数的重新实现
- java - Java Web Service 在本地机器上保持编码,在开发时转换
- spring-mvc - 如何在spring mvc ftl中使用right_pad评估嵌套表达式
- ruby-on-rails - 什么是使用动作邮件发送大量电子邮件的面向性能的方法?
- regex - 仅使用 Google 表单中的某些字词进行响应验证
- appium - 如何使用 Appium 在真实 iOS 设备上自动化我不拥有的 iOS 应用程序
- azure - 在 Azure Functions 2 中,+(加)号是否适用于路由
- regex - 使用 Powershell 将第二次出现的“-”替换为“_”