-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")
7
  • "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. Commented Jul 26, 2022 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. Commented Jul 26, 2022 at 21:34
  • Have you checked this: stackoverflow.com/questions/49307303/… (install script also mentioned on pypi.org/project/pywin32) Commented Jul 26, 2022 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. Commented Jul 26, 2022 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. Commented Jul 26, 2022 at 21:57

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.