0

I am coding an install tool for python modules, for machines that aren't connected to the internet.
The idea is to first use the tool on a machine that has network access, and then use it on local machines.
To do that, I needed to call pip download from my script. I tried using this:

subprocess.run(['py','-m','pip','download','-r','C:/.../libs/Python 3.8/requirements.txt','-d','C:/.../libs/Python 3.8','--python-version','3.8','--only-binary=:all:'])

But I only got an error code claiming that the ssl module in Python is not available.

When used in the cmd, the command above is functional and pip doesn't complain about ssl.
I tried to check if the python I used in VSCode was different from the version in the cmd, but it doesn't seem so.

I looked around stackoverflow and I found this answer: https://stackoverflow.com/a/50255019/18027979.

I tried the following:

subprocess.check_call([sys.executable,'-m','pip','download','-r','C:/.../libs/Python 3.8/requirements.txt','-d','C:/.../libs/Python 3.8','--python-version','3.8','--only-binary=:all:'])

The ssl warning and connection timeout are still showing up, but the libs and their dependencies are successfully downloaded.

I know that the sys.executable arg is checking that the call is using the pip that's currently on runtime, but I am unsure how this helps with the issues I encountered with the first command.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
  • 3
    `sys.executable` uses the same interpreter you're already in; `py` uses the one configured as default. Clearly they're different. Two different interpreters can be two different versions of Python, in which case they're liable to have two different sets of libraries already installed, potentially different sets of libraries _available for download_, etc. – Charles Duffy Apr 18 '23 at 12:49
  • (you might call `python -m pip` with a bunch of arguments that point to Python 3.8, but if that copy of `python` that you pass `-m pip` into isn't a 3.8 release, then you're getting into a place where things are liable to be weird and/or broken). – Charles Duffy Apr 18 '23 at 12:52
  • ...think about `py -3.8 -m pip ...` to ask `py` to _specifically_ run a Python 3.8 interpreter. You want the `-3.8` argument to be passed to `py.exe`, not to `pip`, so it goes at the very front of the list. – Charles Duffy Apr 18 '23 at 12:55
  • I see. This means that I will have to include python interpreters for every single release I want to have those libs available for, which I would rather have avoided. Thanks for the clarification, have a good day ! – be-cieutat Apr 18 '23 at 13:11

0 Answers0