1

Let me begin by saying I am very new to python so I will try to be as concise as possible, but please read my question with that thought in mind and have mercy on my ignorant soul.

I am working with an application, written in C++, that ships with Python version 3.4. The software allows users to write Python scripts and save them to a directory in order to control the program through these custom scripts. However, the Python library that ships with the software doesn't include matplotlib. Is it possible to use the pip installer to install matplotlib in this program's Python directory? I tried using --target with the pip installer, but that has not worked for me. If I cannot use pip, can anyone direct me to some documentation that might help me understand how to add packages to Python shipped within another program?

Furthermore, for future reference, is it possible to upgrade the version of Python within this program to Python 3.7 without access to the program's C++ source code?

Thank you for any input and help, and for not spitefully bashing my poorly posited question.

Edit:
Running path\to\python.exe -m site yielded the following:

C:\>"C:\path\python34\python.exe" -m site
sys.path = [
    'C:\\',
    'C:\\path\\python34\\python34.zip',
    'C:\\path\\DLLs',
    'C:\\path\\lib',
    'C:\\path\\python34',
    'C:\\path\\python34\\lib\\site-packages',
]
USER_BASE: 'C:\\Users\\user\\AppData\\Roaming\\Python' (exists)
USER_SITE: 'C:\\Users\\user\\AppData\\Roaming\\Python\\Python34\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True

Running the command "path\python34\python" "path\pip-20.0.2-py2.py3-none-any.whl\pip" install -U -I pip yields the following output and subsequent error:

Traceback (most recent call last):
  File "C:\path\python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\path\python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\__main__.py", line 16, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\cli\main.py", line 10, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\cli\autocompletion.py", line 9, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\cli\main_parser.py", line 7, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\cli\cmdoptions.py", line 28, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\models\target_python.py", line 4, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_internal\utils\misc.py", line 20, in <module>
  File "C:\path\pip-20.0.2-py2.py3-none-any.whl\pip\_vendor\pkg_resources\__init__.py", line 35, in <module>
  File "C:\path\python34\lib\plistlib.py", line 65, in <module>
    from xml.parsers.expat import ParserCreate
  File "C:\path\python34\lib\xml\parsers\expat.py", line 4, in <module>
    from pyexpat import *
ImportError: DLL load failed: The specified procedure could not be found.
srschoe
  • 11
  • 2
  • Does it actually have an executable Python binary, can you find its path (something like `path/to/python`) and run it? If yes, can you run `path/to/python -m pip`? – sinoroc Mar 10 '20 at 15:15
  • As I suspected. I conclude it's Windows, right? It's probably the _embeddable_ version of Python, it doesn't have the whole standard library. Could you add the output of `path/to/python.exe -m site` to your question in case it is successful and returns something useful. – sinoroc Mar 10 '20 at 15:48
  • Yes, it is windows. I've added the output of that command to the question – srschoe Mar 10 '20 at 15:55
  • I accidentally deleted my response to the first comment which was as follows: "I do not believe it meets all the requirements of a stand-alone executable as I received an error saying it was missing the python dlls. I downloaded and added the appropriate dlls to the directory, tried again, and received this error: C:\path\python34\python.exe: Error while finding spec for 'pip.__main__' (: No module named '_winreg'); 'pip' is a package and cannot be directly executed" – srschoe Mar 10 '20 at 16:05
  • OK, look at [this other answer](https://stackoverflow.com/a/58374558/11138259) for some info. But first maybe try `path/to/python -m ensurepip` (it will probably fail). Second I would download the [_pip_ _wheel_](https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl) directly from [here](https://pypi.org/project/pip/#files) and try to install _pip_ with `path/to/python path/to/pip.whl/pip install pip`. – sinoroc Mar 10 '20 at 16:06
  • Also read this: https://stackoverflow.com/a/48906746/11138259 – sinoroc Mar 10 '20 at 16:17
  • Thank you for all of your help thus far. I tried path/to/python -m ensurepip and it did indeed fail. I then downloaded pip_wheel and tried installing with the suggested command but to no avail with error: "ImportError: DLL load failed: The specified procedure could not be found." I also began following the methods in the other links you suggested. However, before I continue, is the goal of those suggestions to install pip in the path\Scripts folder of the embedded version? If so, it appears pip is already installed in this location. I tried running this pip executable specifically... – srschoe Mar 10 '20 at 16:56
  • ...yet it also failed with the error: Fatal error in launcher: Unable to create process using '"E:\Python34\python.exe" "C:\path\python34\scripts\pip3.exe" --install matplotlib' – srschoe Mar 10 '20 at 16:56
  • Maybe that's what you're already doing, but just in case I will repeat: don't use the `pip.exe` executable, pay attention to always use `path/to/python.exe -m pip somecommand` instead of `path/to/pip.exe somecommand`! Now to try and fix _pip_, maybe you would want to do something like `path/to/python.exe path/to/pip.whl/pip install -U -I pip`. Or skip _pip_ and go straight to installing _matplotlib_: `path/to/python.exe path/to/pip.whl/pip install matplotlib`. But I am afraid, things will be missing from the standard library anyway. It might be still worth trying though. – sinoroc Mar 10 '20 at 17:25
  • I only ran the pip as an executable as a one time as a test. Yet, anytime I try _any_ pip command I receive the error added to the bottom of the question post. I followed the instructions in the other links you provided to me as well. I believe the issue may lie in the fact that this embedded version of Python (3.4) was manually embedded before python embeddable zip files were available for download (beginning with python 3.5.0?). Again, it seems pip is already installed in the scripts folder, but I cannot overcome the error I receive with every pip command I enter, shown above. – srschoe Mar 10 '20 at 19:13
  • I see. Well, then there is no easy solution I can think of. You could install a full Python 3.4 (or whatever the exact version is) in parallel, and (I do not guarantee any results, I haven't tried and this could mess up things) **1.** Either use this other Python to install _matplotlib_ and its dependencies in the _site-packages_ directory of the embedded one. Maybe it will be the same directory by default anyway, or with `pip install --target`. **2.** Or install _matplotlib_ as normal with the other Python and then one by one copying the missing files into the embedded one until it works. – sinoroc Mar 10 '20 at 19:26
  • 1
    That seems like it might be the best solution for the time being. Thank you for all your help sinoroc! – srschoe Mar 10 '20 at 19:40

0 Answers0