[docs] Fw: Embedding Python in Another Application Import Statement Bug

Ibarra, Jesse jibarra4 at live.nmhu.edu
Tue Jun 25 10:41:04 EDT 2019


Is this ticket still unsolved?

________________________________
From: Ibarra, Jesse
Sent: Tuesday, June 18, 2019 4:58 PM
To: docs at python.org
Cc: Koh, Aik-Siong
Subject: Fw: Embedding Python in Another Application Import Statement Bug



________________________________
From: Ibarra, Jesse
Sent: Tuesday, June 18, 2019 4:56 PM
To: python-list at python.org
Cc: Koh, Aik-Siong
Subject: Embedding Python in Another Application Import Statement Bug

I am running CentOS7:

[jibarra at redsky ~]$ uname -a
Linux redsky.lanl.gov 3.10.0-957.21.2.el7.x86_64 #1 SMP Wed Jun 5 14:26:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I am using Python3.6:

[jibarra at redsky ~]$ python3.6
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

I have successfully ran:
https://docs.python.org/3.6/extending/embedding.html#very-high-level-embedding
https://docs.python.org/3.6/extending/embedding.html#pure-embedding
https://docs.python.org/3.6/extending/embedding.html#extending-embedded-python

I then modify example:
https://docs.python.org/3.6/extending/embedding.html#pure-embedding

To include a class definition without an import statement inside of the Python code. I succesfully run the program and get a result.

The program calls PyImport_Import(pName):
pName is a PyObject equal to "without_numpy_import.py" or "without_numpy_import"

To execute run the following:

[jibarra at redsky NoImportNumpy2]$ gcc -o without_numpy2 -I /usr/include/python3.6m without_numpy2.c -L /usr/bin/python3.6-config -lpython3.6m
[jibarra at redsky NoImportNumpy2]$ ./without_numpy2
Result of: 2 * 2
Return of call : 4
Result of: 2 * 2
Return of call : 4

But when I run the same code and include an import statement in the Python code such as "import numpy" I get:

[jibarra at redsky ImportNumpy2]$ gcc -o with_numpy2 -I /usr/include/python3.6m with_numpy2.c -L /usr/bin/python3.6-config -lpython3.6m
[jibarra at redsky ImportNumpy2]$ ./with_numpy2
Result of: 2 * 2
Return of call : 4
Segmentation fault (core dumped)

I can confirm that I do have numpy library:
[jibarra at redsky ~]$ python3.6
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> print(type(a))
<class 'numpy.ndarray'>

I have included two examples of this:
Two_Import_Call
  Has a in-depth call to Python file,class, and variables
Two_Import_Simple
  Has a very simple call to Python file ONLY

Both as these folders contain code with the same issue regarding import statements and running the code again after Py_Finalize();


Please advise.

Thanks,
Jesse Ibarra

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20190625/aba25872/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Python_Import_Problem.tar.gz
Type: application/gzip
Size: 1984 bytes
Desc: Python_Import_Problem.tar.gz
URL: <http://mail.python.org/pipermail/docs/attachments/20190625/aba25872/attachment-0001.bin>


More information about the docs mailing list