Py_InitializeEx() in CygWin64's Python2.7

Gisle Vanem gvanem at yahoo.no
Wed Jul 1 17:44:42 CEST 2015


I've written a C-program that embeds Python 2.7.
It has worked fine for several years using MingW or MSVC. Now I'd like
to support the python2.7.exe that comes with CygWin64.

But it seems to fail inside 'Py_InitializeEx(0)' where it just prints:
   ImportError: No module named site

What? Does really all Pythons needs a 'PYTHONPATH' set to point to the
site.py? Or is it only CygWin that is special here? Since if I do a
"set PYTHONPATH=/usr/lib/python2.7" in my shell, my program works.

These are some of the func-ptr and arguments I use during init:

  Py_SetProgramName ("/cygdrive/f/gv/VC_project/EnvTool/src/envtool.exe")
  Py_SetPythonHome ("/usr/lib/python2.7")
  Py_InitializeEx(0)   << libpython2.7.dll chokes inside here for a mysterious reason.

I maybe naively assumes calling 'Py_SetPythonHome' is doing part of
what parsing the PYTHONPATH should do. But it doesn't seems so.

If I from my cmd-line do a:

c:\> f:\CygWin64\bin\python2.7.exe -c "import sys; print (sys.modules)"

I can see:
   <module 'site' from '/usr/lib/python2.7/site.pyo'>

So what could be the reason it's not able to load and parse it
without a 'PYTHONPATH' set explicit?

-- 
--gv


More information about the Python-list mailing list