Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed Python Zip file throws error?

I am trying to embed the python zip file in my application. I downloaded the zip file from the python site, (the win32 one).

This is the code I use to set the python path

#include <Python.h>
...
std::wstring exe_dir = L"\\exe\\path";
std::wstring python_path;
python_path += exe_dir + L"python-3.5.1-embed-win32.zip";
Py_SetPath(python_path.c_str());

Py_Initialize(); // Error : "Py_Initialize: unable to load the file system codec"

...

But no matter what I do, the app throw the same error all the time. Even if I play around with various path.

How can I embed the zip file in my app?

like image 705
FFMG Avatar asked Feb 27 '16 06:02

FFMG


People also ask

How do I install an embedded ZIP file in Python?

Installing PythonDownload the embeddable zip file from the link https://www.python.org/downloads/release/python-374/. Extract the archive or zip file into a physical drive location. Let's say under C drive. So the extracted python root directory is C:\python-3.7.

What is embedded zip Python?

The embeddable package. New in version 3.5. The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.


1 Answers

There is another zip file inside "python-3.5.1-embed-win32.zip".

python35.zip

And that file is the one that needs to be added.

#include <Python.h>
...    
std::wstring exe_dir = L"\\exe\\path";
std::wstring python_path;
python_path += exe_dir + L"python35.zip";
Py_SetPath(python_path.c_str());

Py_Initialize();    
...

I would be interested to know what the other files are for, (or if this is the correct way to use it) ...

like image 75
FFMG Avatar answered Sep 20 '22 20:09

FFMG