Why can't I add pip to the version of Python that comes with Blender 2.91.2? Short version: I need to install external modules for use within Blender, but can't for the reasons given below.
I'm on macOS 10.14.3 with Blender 2.91.2, which includes Python 3.7. I want to be able to use modules in Python that are not included in the Blender package. I've seen a number of posts here and on other sites about how to do this, but I can't get that version of Python to work from outside Blender and I can't do it from within Blender. This Mac is still running on original settings for Python, so the default Python for the Mac command line is 2.7. (I'd like to upgrade to the current OS version, but still haven't replaced some programs that won't work under the next update.)
I tried using the script given here to install pip:
import subprocess
import sys
import os

# path to python.exe
python_exe = os.path.join(sys.prefix, 'bin', 'python.exe')

# upgrade pip
subprocess.call([python_exe, &quot;-m&quot;, &quot;ensurepip&quot;])
subprocess.call([python_exe, &quot;-m&quot;, &quot;pip&quot;, &quot;install&quot;, &quot;--upgrade&quot;, &quot;pip&quot;])

# install required packages
subprocess.call([python_exe, &quot;-m&quot;, &quot;pip&quot;, &quot;install&quot;, &quot;package_name&quot;])

I modified the executable name from &quot;python.exe&quot; to &quot;python3.7m&quot;, which is what is used in the Mac version. I even verified the path name to make sure it was all correct. Whenever I try to run it, when I get to the first line under &quot;# upgrade pip&quot;, I get a return code of -6. I tried variations and I simply cannot run a subprocess using the Python executable from within the Blender Python command line.
There are a number of links for installing pip by using the Python executable installed with Blender. Whenever I try to do that, I get:

Fatal Python error: initfsencoding: unable to load the file system codec   File

&quot;/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py&quot;,
line 123
raise CodecRegistryError,
^ SyntaxError: invalid syntax
Current thread 0x00000001183265c0 (most recent call first): Abort
trap: 6

So to install pip, I have to be able to, in some way, run the Python executable included with Blender, but I can't run it. I'm assuming it needs settings that are different from my system environment variables, but I don't know what I'd have to change or how I'd pass that change on that instance of Python.
I am aware there is a pip module and I have tried to import it, but I can't find documentation on it online and all I get when I try &quot;help('pip')&quot; is this:

Help on package pip:
NAME
pip
PACKAGE CONTENTS
main
_internal (package)
_vendor (package)
VERSION
19.2.3
FILE
/Applications/Blender.app/Contents/Resources/2.91/python/lib/python3.7/site-packages/pip/init.py

I also changed the python subdirectory inside the Blender directory to python-old, as suggested in some web pages. When I did that, Blender would not start. (I'm starting Blender from the command line so I can read Python error messages.)
What I need is a way to be able to run pip from the Python instance included with Blender so I can install Pillow (among other modules). But, if possible, I'd like to know what is going on that makes the Blender Python executable not work when I try it from the command line and how I could fix that.
I had to go through several other issues to pin this down, including another question on stack Overflow, where I was not getting much help. I'll include what I can here. That'll be more than most people want to read, but if you have this problem, skim it because you might find helpful stuff in here.
The bottom line is that I was setting PYTHONPATH in .bash_profile. When I bought this current iMac, Python 2.7 was the standard on an install. At some point (and I had forgotten this), Apple changed to 3.x as the standard. That crashed some of my scripts, so I set PYTHONPATH (again, in .bash_profile) to point to all the 2.7 libraries, so my scripts would continue to look there.
I finally figured out that any 3.x version of Python was crashing on my system and 2.x was running. I thought that was probably a configuration issue and I'd have to find some config file to fix somewhere, but, all along, it was in the .bash_profile. Once I changed all the paths in there to point to 3.7 instead of 2.7, everything started working fine. Python 3 executables were working fine and even the 2.x ones were still working. (And more of my scripts than I expected worked fine under 3.x.)
Once I got that working, I wrote a batch file I can run in bash to set PYTHONPATH to point to the directories Blender uses when it runs Python in its own environment then run the Blender instance of Python. It works fine and that let me follow instructions in a number of places to use ensurepip to install pip and then to install Pillow.