首页 > 解决方案 > 没有模块名称 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))

标签: python

解决方案


毕竟你不需要导入 pywin。你没有使用它。而是将导入更改为以下内容,程序应该可以正常工作。

#from pythonwin import pywin
import win32api, win32con, time, math

而且你没有做任何事情来在你的程序中打开 chrome。这只会用你的指针在屏幕上画一个圆圈(你显然可以看到)。


推荐阅读