0
votes

I'm getting this error

C:\Users\Rayner\Desktop>python try.py Traceback (most recent call last): File "try.py", line 1, in from pythonwin import pywin ImportError: No module named pythonwin

when running this code

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))
1
Im using python 2.7.5 and pywin32-218.win-amd64-py2.7user11308569
maybe you have to pythons installed and you installed pywin in one python but code runs with second python. I could also asked: did you install this pywin32 ?furas
why do you import pythonwin if you don't use it in code ?furas
from command prompt, run: python and then try to import pythonwin. if you don't get any error then there is something else wrong. However, if you get an error, install using: pip install pythonwin or conda install pythonwinSanV
BTW: you import win64api, win64con but later you use win32api, win32con.furas

1 Answers

0
votes

You don't need to import pywin afterall. You are not using it. Instead change the imports to the following and the programs should work fine.

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

And you are not doing anything to open chrome in your program. This will only draw a circle with your pointer on the screen (which you obviously can see).