Jump to content
marcocir

Adding libraries to a Python embedded installation

Recommended Posts

Hi all.

I have a Delphi P4D Windows application that I would to distribute as a single zip file.

I use an embedded 3.8.9 64 bit version of Python in a \python folder of my application , where I have installed numpy and matplotlib, libraries that my app needs to use as well.

If I try to copy the whole application folder, with \python subfolder, in another PC, and run the code where Python try to import numpy, I always get a ModuleNotFoundError : No module named 'numpy'  (matplotlib is the next import module in the script, but Python script aborts on numpy import line, I think).
If I don't try yo import and use these libraries my application runs just fine from the zip file.
I've used Google to search for a hack but no solution seems to help: someone could suggest how to add Numpy (and MatPlotLib, I think this should be the same) to that zip file, so my customer can simply de-zip my installation file and use my Delphi application?
Thanks!

 

Edited by marcocir
  • Like 1

Share this post


Link to post

can you execute matplotlib code  if you use you /python folder and python.exe  inside this folder? 

how are you setting the  reference  to pythonDLL and pythonDLL  path in your application?

I followed the config of Tpythonengine from here  ....   because different PC's have many different python settings / also drives me crazy  ...  to get one application running on different CPUs.

did not want to go for my own python installation to be distributed with my application  .....

 

Edited by bernhard_LA

Share this post


Link to post

Thank you  Bernhard.
No, I couldn't use the external libraries either way.
Having to use the a different version of Python from any other that was eventually registered, I set the DLL's path on the OnBeforeLoad event of the Engine. 
The problem was only with Python external libraries
Anyway, I found a solution.

 

1) Follow this StackOverflow answers:
https://stackoverflow.com/questions/49737721/adding-packages-to-python-embedded-installation-for-windows


2) I fixed the error, and succesfully imported and used numpy and matplotlib with the embedded version of Python adding

lib\site-packages

 

entry to pythonXX._pth file, inside embedded python folder.

Now I have a zip file that I can expand on a generic PC and run my P4D application with numpy and matplotlib plots (as SVG) 😉 

 

 

 

 

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×