Title: Example in section 5.3 "Pure Embedding" doesn't work.
Type: behavior Stage: test needed
Components: Documentation, Extension Modules Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Ramchandra Apte, docs@python, fkochem, georg.brandl, georg.brandl, jhao, vstinner, wrstuden
Priority: normal Keywords:

Created on 2006-01-06 19:23 by wrstuden, last changed 2020-12-29 04:39 by orsenthil.

Repositories containing patches
Messages (7)
msg60866 - (view) Author: Bill Studenmund (wrstuden) Date: 2006-01-06 19:23
I want to use Python to script an existing application.
So I was trying the code on and
found it didn't work.

I am using pkgsrc on NetBSD.

I have run into two issues. First,
PyDict_GetAttrString() does not exist. I have found
this to be true for both Python 2.2 and 2.4, the two
versions I currently have installed.

I made the simple change to use
PyObject_GetAttrString(), which looks right.

Second, python can't find the module. I named the file, and it wouldn't load.

It turns out that I had to set PYTHONPATH in my
envirnment to make it work. Setting it to '' (empty
string) worked.

The odd thing about the path issue is that if I ran the
python interpreter, it was able to find the module w/o
my changing the environment.
msg60867 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-01-06 19:33
Logged In: YES 

The PyDict_GetAttrString issue is corrected in the current
devel docs.

No clue about the other.
msg60868 - (view) Author: Bill Studenmund (wrstuden) Date: 2006-01-06 22:48
Logged In: YES 

Great to hear about PyDict_GetAttrString(). I assume that
PyObject_GetAttrString() was the correct change?

It turns out the second issue deals with path processing in
the embedded code being somehow different from processing in
the interpreter. I think the interpreter sets something up
that isn't present for the embedded example. I will really
appreciate it if we could figure out what's different and
add it to the docs. The pictured behavior for "call" is
exactly what I want, but not what I get.

To be more specific, I had my code print Py_GetPath(), and I
compared that with sys.path from the interpreter.

C code looking for (which is in '.'):

> ./obj.i386/test foo
Path is
ImportError: No module named foo
utest: loading module foo: No such file or directory

In the python interpreter:

> python2.4
Python 2.4.1 (#1, Dec 28 2005, 15:58:29) 
[GCC 3.3.3 (Wasabi NetBSD nb3 20040520)] on netbsd3
Type "help", "copyright", "credits" or "license" for more
>>> import sys
>>> print sys.path
['', '/usr/pkg/lib/', '/usr/pkg/lib/python2.4',

The key difference is the '' at the front of the path in the

Any thoughts? Is there a different list or FAQ I should look at?
msg182510 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013-02-20 14:29
Is this still valid?
msg212842 - (view) Author: Fabian Kochem (fkochem) Date: 2014-03-06 21:29
I just fell over the PYTHONPATH='' bit aswell. So yes, this is still valid.
msg221302 - (view) Author: Jun Hao (jhao) Date: 2014-06-22 19:47
I have updated the example in the doc. This default behavior is introduced because of security reason as detailed in
msg348609 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-29 11:27
This issue is 13 years old, inactive for 5 years, has a patch: it's far from being "newcomer friendly", I remove the "Easy" label.
Date User Action Args
2020-12-29 04:39:25orsenthilsetkeywords: - easy
versions: + Python 3.10, - Python 2.6
2019-07-29 11:27:11vstinnersetnosy: + vstinner
messages: + msg348609
2014-06-22 19:47:50jhaosethgrepos: + hgrepo261

messages: + msg221302
nosy: + jhao
2014-03-06 21:29:09fkochemsetnosy: + fkochem
messages: + msg212842
2013-02-20 14:29:51Ramchandra Aptesetnosy: + Ramchandra Apte
messages: + msg182510
2010-08-26 16:24:30BreamoreBoysetassignee: georg.brandl -> docs@python
nosy: + docs@python
2009-04-22 14:35:57ajaksu2setkeywords: + easy
2009-03-20 23:51:12ajaksu2setnosy: + georg.brandl
versions: + Python 2.6
assignee: georg.brandl
components: + Documentation
type: behavior
stage: test needed
2006-01-06 19:23:52wrstudencreate