You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Example in section 5.3 "Pure Embedding" doesn't work. #42771
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
multiply.py, 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.
The PyDict_GetAttrString issue is corrected in the current
devel docs.
No clue about the other.
wrstuden commented on Jan 6, 2006
wrstudenmannequin
MannequinAuthor
More actions
Logged In: YES
user_id=148388
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 foo.py (which is in '.'):
./obj.i386/test foo
Path is
'/usr/pkg/lib/python24.zip:/usr/pkg/lib/python2.4/:/usr/pkg/lib/python2.4/plat-netbsd3:/usr/pkg/lib/python2.4/lib-tk:/usr/pkg/lib/python2.4/lib-dynload'
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
information.
>>> import sys
>>> print sys.path
['', '/usr/pkg/lib/python24.zip', '/usr/pkg/lib/python2.4',
'/usr/pkg/lib/python2.4/plat-netbsd3',
'/usr/pkg/lib/python2.4/lib-tk',
'/usr/pkg/lib/python2.4/lib-dynload',
'/usr/pkg/lib/python2.4/site-packages']
The key difference is the '' at the front of the path in the
interpreter.
Any thoughts? Is there a different list or FAQ I should look at?
The earliest link to the original issue I could find is this, which has a section matching the title, and the example in that does seem to correspond to the modern link here.
Activity
wrstuden commentedon Jan 6, 2006
I want to use Python to script an existing application.
So I was trying the code on
http://docs.python.org/ext/pure-embedding.html 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
multiply.py, 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.
birkenfeld commentedon Jan 6, 2006
Logged In: YES
user_id=1188172
The PyDict_GetAttrString issue is corrected in the current
devel docs.
No clue about the other.
wrstuden commentedon Jan 6, 2006
Logged In: YES
user_id=148388
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 foo.py (which is in '.'):
In the python interpreter:
The key difference is the '' at the front of the path in the
interpreter.
Any thoughts? Is there a different list or FAQ I should look at?
4 remaining items
jhao commentedon Jun 22, 2014
I have updated the example in the doc. This default behavior is introduced because of security reason as detailed in http://bugs.python.org/issue5753
vstinner commentedon Jul 29, 2019
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.
slateny commentedon Jun 13, 2022
The earliest link to the original issue I could find is this, which has a section matching the title, and the example in that does seem to correspond to the modern link here.
ashm-dev commentedon Nov 13, 2025
Ping. Is this issue still relevant?
vstinner commentedon Nov 13, 2025
Let's close this old issue. The context is now outdated.
The doc now lives at: https://docs.python.org/dev/extending/embedding.html.
If someone is still impacted by the issue, please open a new issue.