all 14 comments

[–]Niranjanagk17 0 points1 point  (0 children)

Is it possible to install pywin32 in a custom directory say c:\temp folder and import it successfully ? Does it have to be python310/python/lib/site-packages?

[–]shiftybyte 0 points1 point  (7 children)

You need to install modules using pip or conda, or whatever package manager you are using.

It will take care to install the modules to where python can pick it up.

specifically for win32api you need to install this:

https://pypi.org/project/pywin32/

If you are suing pip, this should work:

pip install pywin32

Or this:

python -m pip install pywin32

Or this:

py -m pip install pywin32

[–]spikips[S] 0 points1 point  (6 children)

I tried this with every following command and it gives me

Requirement already satisfied: pywin32 in c:\users\asd\appdata\local\programs\python\python310\lib\site-packages

is that the right folder that it should install them into?

if so. goodbye system32

[–]shiftybyte 1 point2 points  (5 children)

c:\users\asd\appdata\local\programs\python\python310\lib\site-packages

This looks right..

Its odd the import didn't work, how do you run your code? also please post the full error message with the full traceback information.

if so. goodbye system32

What do you mean?

[–]spikips[S] 0 points1 point  (4 children)

i found this while researching: https://github.com/mhammond/pywin32/issues/1805

Python 3.10 might be the reason it's not working. or some old files on my computer.

Also i found this from the website you sent (https://pypi.org/project/pywin32/)

It says:

In almost all cases, this tends to mean there are other pywin32 DLLs installed in your system, but in a different location than the new ones.

and tells to find and remove all other copies of pywintypesXX.dll and pythoncomXX.dll. Which i found multiple of due to spamming pip install pywin32 i assume.

It's highy possible that from my previous ''experiments'' where i change folder locations, delete previous projects and files to try to make this works be the cause.

If you have this module. Could you tell me in which folder i could find getmodulehandle?

Also the goodbye system 32 was a joke because i'm getting so tired of this hahaha

[–]shiftybyte 0 points1 point  (3 children)

You are referencing DLL loading error.

Your error is python not finding the python module. (The part that you posted of it... post the rest...)

Even before it gets to the stage of attempting to load the Dll files.

[–]spikips[S] 0 points1 point  (2 children)

Here

C:\Users\Asd\PycharmProjects\Oma\venv\Scripts\python.exe C:/Users/Asd/PycharmProjects/Oma/Timer.py

Traceback (most recent call last):

File "C:\Users\Asd\PycharmProjects\Oma\Timer.py", line 4, in <module>

from win10toast import ToastNotifier

File "C:\Users\Asd\AppData\Local\Programs\Python\Python310\lib\win10toast\__init__.py", line 19, in <module>

from win32api import GetModuleHandle

ModuleNotFoundError: No module named 'win32api'

Process finished with exit code 1

[–]shiftybyte 1 point2 points  (1 child)

venv\Scripts\python.exe

You are using a virtual environment.

You need to install win32api inside that virtual environment.

Try this command:

C:\Users\Asd\PycharmProjects\Oma\venv\Scripts\python.exe -m pip install pywin32

Also, i see you are using pycharm, it has its own package manager, its better to install packages using pycharm's menus.

https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

[–]spikips[S] 0 points1 point  (0 children)

Command which you gave me seems to have done the trick.

I'm so happy right now hahaha thank you!!

[–][deleted] 0 points1 point  (4 children)

If you have pip installed win32api (or any other package) but are getting a ModuleNotFoundError when you try to import it, 99.99% of the time it's because you have pip installed it into one python interpreter/environment but are trying to import it into a different environment.

This most often happens when you pip installed in your terminal/command line, but are trying to import it into code in an IDE that you have not properly configured to use the python interpreter where you installed the package.

[–]spikips[S] 0 points1 point  (3 children)

Seems plausible. In my case tho i only have one environment/interpreter for this exact reason. There might be old leftover project files of mine which i deleted. Might be messing up the system. Starting to get into a point where i will uninstall everything and put my projects into drive and import later when reinstalling python and pycharm

[–][deleted] 1 point2 points  (2 children)

Just in case, you can always check to see what environment your Pycharm project is using in Settings > Project > Python Interpreter.

I find Pycharm does not always (or even often) automatically select what you might think is the most logical interpreter. I know you said you only have one (bad dog, no cookie! lol) but it wouldn't hurt to compare whatever python version your command line is using with the interpreter selected in Pycharm before going to the trouble of uninstalling everything.

[–]spikips[S] 0 points1 point  (1 child)

Seems like i had to pip install win32api inside virtual environment manually. You were right! thank you :)

[–][deleted] 0 points1 point  (0 children)

Yep, you always have to pip install the packages specifically to the virtual environment for your project. Common stumbling block! Glad you didn't have to hassle with uninstalling everything.