-1

I'm using Python 3 and working in Pycharm.

I was able to get pywin32 and win32com working on one project, but since I have tried importing them into a new project, they don't seem to be working. At first I was getting No module named 'win32api', but I updated the win32com\__init__.py from import win32api to from win32 import win32api. That seems to have fixed the initial error, but now I'm getting No module named '_win32com'. This seems to be from issues with \pythoncom\__init__.py maybe?

I've tried uninstalling and reinstalling pywin32 and pypiwin32 as well.

Example of code here:

import win32com.client as win32
xlapp = win32.DispatchEx("Excel.Application")
wbe = xlapp.workbooks.open(r"C:\Users\me\example.xlsx")
Nin17
  • 2,821
  • 2
  • 4
  • 14
scorbin
  • 9
  • 5
  • *"but since I have tried importing them into a new project, they don't seem to be working"* How did you try to "import them into a new project"? I think it might be a virtual environment issue (ie. the packages were not globally installed), but that's just a guess. – Uncle Dino Jul 26 '22 at 20:49
  • 1
    I believe that is correct, they are not installed globally right now. By import into a new project, I mean I started a new project, imported using the code above and making sure the packages are installed, etc. That's how I did it in the first project without issue. – scorbin Jul 26 '22 at 21:34
  • Have you checked this: https://stackoverflow.com/questions/49307303/installing-the-pypiwin32-module (install script also mentioned on https://pypi.org/project/pywin32/) – Uncle Dino Jul 26 '22 at 21:41
  • I haven't seen that specific post, but I've seen similar. I've got pypiwin32 installed as well, it's loaded in the project. I've tried that post_install script as well and that doesn't work. Although, I haven't tried deleting any copies of the dll's. Not sure where those should be located. – scorbin Jul 26 '22 at 21:56
  • I would also just note that I am seeing the error for '_win32com' with an underscore, while every other post I have seen is for 'win32com'. I am not sure if that is important. – scorbin Jul 26 '22 at 21:57
  • I suggest searching for "_win32com" in that directory, to see where it supposed to be loaded. Since you have a working version, you might compare them file-by-file. – Uncle Dino Jul 26 '22 at 22:06
  • I guess I'm not sure what I'm suppose to be looking for. I only see _win32com being imported in the ```__init__.py``` of the pythoncom folder of the new project. I actually don't see a pythoncom folder in the first project. – scorbin Jul 26 '22 at 22:41

1 Answers1

0

I decided to try again with a new project and install the packages globally and that has fixed the issue. Still not sure why it wasn't working when installing locally, but using global installs seems to be good solution.

scorbin
  • 9
  • 5