0

I have a python program that executes os.system("pip install pywin32") but for some reason it doesn't install it. So if it's possible to put the files of the pywin32 package in the working directory then no need to execute os.system("pip install pywin32") and the package would be already downloaded.

Anyone knows how to do that?

The_Fishy
  • 143
  • 10
  • Are you looking for how to install a package [using setup.py](https://stackoverflow.com/a/1472014/11323371) ? – InsertCheesyLine Aug 09 '22 at 06:01
  • 2
    "*…for some reason it doesn't install…*" What reason? Any error message? Does `pip` run under the same Python as the interpreter used for the current script? – phd Aug 09 '22 at 07:58
  • 2
    You are trying to solve the wrong problem. Try to figure out why your `pip install` is not working when it should. This will probably not be the last package that you need – FlyingTeller Aug 09 '22 at 07:59

2 Answers2

0

To do so, we should at first convert the python program to an executable (.exe) using pyinstaller with the command:

pyinstaller myFile.py --noconfirm --onefile --console --icon=icon.ico --name myName you can find more options in the pyinstaller docs.

Then this executable file that has been created will detect all the packages that has been imported in the initial python program and will install them when the executable is ran for the first time.

If you wish to store packages that hasn't been imported in the initial python file use the option --hidden-import <Package Name> to your conversion command.

The_Fishy
  • 143
  • 10
-2

Use this:

py -m pip install --upgrade pip [The package]
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92