0

I added some code snippets to python script and sent him to client. There is new library, does the the other side to install also package? pip install pywin32

code that added by me to script is;

import win32com.client
xl = win32com.client.Dispatch("Excel.Application")  #instantiate excel app

wb = xl.Workbooks.Open(r'C:\Users\jay\Desktop\PythonInOffice\python_run_macro\macro.xlsm')
xl.Application.Run('macro.xlsm!Module1.macro1("Jay")')
wb.Save()
xl.Application.Quit()

From answers': if I write the code below do I need to install sys and subprocess separetely also?

import subprocess
import sys

def install('pywin32'):
    subprocess.check_call([sys.executable, "-m", "pip", "install", 'pywin32'])
STerliakov
  • 4,983
  • 3
  • 15
  • 37
xlmaster
  • 659
  • 7
  • 23

1 Answers1

2

Hope below code helps

Normally check for if package there if not installs it

import sys
import subprocess
import pkg_resources

required = {'pywin32'}
installed = {pkg.key for pkg in pkg_resources.working_set}
missing = required - installed

if missing:
    python = sys.executable
    subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)

NOTE:- if proxy being used, it won't work. on check_call enter proxy details to install

Deepak
  • 430
  • 1
  • 7
  • 14
  • if you could describe more in detail every step that would be useful much. – xlmaster Oct 13 '22 at 19:26
  • I edited the code, could you look up please due @Ahmed AEK – xlmaster Oct 13 '22 at 19:29
  • @Ahmed AEK, I trie your code with `tkinter` it gave me an error `ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter` – xlmaster Oct 19 '22 at 15:22