0

I am new to Python. I am trying to write a program where I have to check and install any missing modules at the time of execution of the code. I am using the below code provided in the solution here.

# Code to check and install missing modules

import pip

# Define function to install missing modules

def install(package):
    pip.main(['install', package])

# Call funtion and install missing module

if __name__ == '__main__':
    install('win32com.client')

When I try executing this, I get the below message. Even when I tried replacing install('win32com.client') by install('win32com'), I still get a similar message. The code works if I used it to check and install pandas module.

Collecting win32com.client
[31m  Could not find a version that satisfies the requirement win32com.client (from versions: )[0m
[31mNo matching distribution found for win32com.client[0m

What am I doing wrong? How do I install the win32com.client module using the code I have provided above? This needs to be checked and installed at the time of execution and should have no manual intervention. I am using Python 3.6.4 and my OS is Windows x64 bit. Any guidance on this would be appreciated.

Code_Sipra
  • 1,571
  • 4
  • 19
  • 38

1 Answers1

0

try install('pypiwin32') instead of install('win32com.client')

weakit
  • 216
  • 3
  • 7
  • I was successfully able to install the module `pypiwin32` using `install('pypiwin32')`. But when I try to `import win32com.client`, I get the message ``from pypiwin32 import * ModuleNotFoundError: No module named 'pypiwin32'``. Not sure if it worked. – Code_Sipra Jan 06 '18 at 15:43
  • @Code_Sipra `pypiwin32` is not a module name, it's only a name of a PYPI entry. You need to import `win32com.client`. – ivan_pozdeev Jan 06 '18 at 15:49