2

I'm new to python but not programming, so please bear with me..

I am attempting to write a python script that utilizes the win32com.client module but am running into a strange occurrence. If I initialize the python shell in the command prompt and manually type in import win32com.client, the command processes just fine and I can use the module with no issues.

However, if i code that import line into the .py file and try to run the file through the command prompt (just by typing foo.py) it tells me that the win32com module cannot be found.. I have the python27 directory path included in my environment variables as well as my PythonProjects path.

Example Follows:

import win32com.client

def foo(): <CODE HERE>

Upon execution:

File C:\PythonProjects\Foo.py, line 1, in import win32com.client ModuleNotFoundError: No module named 'win32com'

Thank you in advance for any/all help.

Parfait
  • 87,576
  • 16
  • 87
  • 105
  • You might have two different Python versions installed. In command prompt or PowerShell, please show the command you ran just before the `import` line. Simply, how did you initialize the Python shell? – Parfait Jun 11 '17 at 15:06
  • I simply open the cmd prompt and type "python" and this opens the shell. Then it shows the normal header with version info, etc. and the ">>>" line. Then I enter "import win32com.client" and it displays another ">>>" line. To test the module, I entered 'shell = win32com.client.Dispatch("WScript.Shell")', then tried shell.SendKeys("A") and this printed an "A" into the python shell, which is what led me to believe it was all working fine. I hope I understood your reply correctly, and sorry for the delayed response. I'm on call for work and it's been a busy weekend :( –  Jun 11 '17 at 16:21
  • Is there an easy way to check for multiple installed versions? Mine says Python 2.7.6 –  Jun 11 '17 at 16:33
  • Hmmm...very strange error. How did you create .py script? Does it have a [shebang](https://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script) line at very top? Try running in IDLE? And carefully check module spelling. – Parfait Jun 11 '17 at 21:39

0 Answers0