<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Splunk Python interpreter not recognizing C library module? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/618998#M10827</link>
    <description>&lt;P&gt;I am currently attempting to build in a new command. This command includes code from the msgspec python package. Within the package is a C library which is referenced as a module by the other functions of the package.&lt;/P&gt;
&lt;P&gt;Testing on my Splunk Ubuntu server and base python3 versions 3.6, 3.7, 3.8, 3.9, and 3.10, this package works without issue. When I attempt to run the same package reference from a python script called via the splunk command line, I receive an error.&lt;BR /&gt;&lt;BR /&gt;Given I can successfully run a test script from the same &amp;lt;app&amp;gt;/bin directory as my splunk commands using the same modules, is there anything in Splunk's use of the python interpreter that would prevent Splunk from using Python's built-in C-extension library?&lt;/P&gt;
&lt;P&gt;Error code example:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;_core&lt;/EM&gt;&amp;nbsp; --&amp;gt; reference: &lt;A href="https://github.com/jcrist/msgspec/blob/main/msgspec/_core.c" target="_blank" rel="noopener"&gt;https://github.com/jcrist/msgspec/blob/main/msgspec/_core.c&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;Successfully created new dispatch directory for search job. sid=b762c107adc97090_tmp dispatch_dir=/opt/splunk/var/run/splunk/dispatch/b762c107adc97090_tmp
10-31-2022 13:33:02.556 INFO  ChunkedExternProcessor [782335 searchOrchestrator] - Running process: /opt/splunk/bin/python3.7 /opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/&amp;lt;base_script&amp;gt;.py
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr: Traceback (most recent call last):
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/&amp;lt;base_script&amp;gt;.py", line 14, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from &amp;lt;parse_script&amp;gt; import &amp;lt;parse_function&amp;gt; as &amp;lt;function&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/&amp;lt;parse_script&amp;gt;.py", line 3, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from msgspec.json import encode, decode
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/msgspec/__init__.py", line 1, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from ._core import (
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr: ModuleNotFoundError: No module named 'msgspec._core'
10-31-2022 13:33:02.685 ERROR ChunkedExternProcessor [782335 searchOrchestrator] - EOF while attempting to read transport header read_size=0
10-31-2022 13:33:02.708 ERROR ChunkedExternProcessor [782335 searchOrchestrator] - Error in '&amp;lt;command&amp;gt;' command: External search command exited unexpectedly with non-zero error code 1.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 14:37:25 GMT</pubDate>
    <dc:creator>corkster919</dc:creator>
    <dc:date>2022-11-01T14:37:25Z</dc:date>
    <item>
      <title>Splunk Python interpreter not recognizing C library module?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/618998#M10827</link>
      <description>&lt;P&gt;I am currently attempting to build in a new command. This command includes code from the msgspec python package. Within the package is a C library which is referenced as a module by the other functions of the package.&lt;/P&gt;
&lt;P&gt;Testing on my Splunk Ubuntu server and base python3 versions 3.6, 3.7, 3.8, 3.9, and 3.10, this package works without issue. When I attempt to run the same package reference from a python script called via the splunk command line, I receive an error.&lt;BR /&gt;&lt;BR /&gt;Given I can successfully run a test script from the same &amp;lt;app&amp;gt;/bin directory as my splunk commands using the same modules, is there anything in Splunk's use of the python interpreter that would prevent Splunk from using Python's built-in C-extension library?&lt;/P&gt;
&lt;P&gt;Error code example:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;_core&lt;/EM&gt;&amp;nbsp; --&amp;gt; reference: &lt;A href="https://github.com/jcrist/msgspec/blob/main/msgspec/_core.c" target="_blank" rel="noopener"&gt;https://github.com/jcrist/msgspec/blob/main/msgspec/_core.c&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;Successfully created new dispatch directory for search job. sid=b762c107adc97090_tmp dispatch_dir=/opt/splunk/var/run/splunk/dispatch/b762c107adc97090_tmp
10-31-2022 13:33:02.556 INFO  ChunkedExternProcessor [782335 searchOrchestrator] - Running process: /opt/splunk/bin/python3.7 /opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/&amp;lt;base_script&amp;gt;.py
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr: Traceback (most recent call last):
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/&amp;lt;base_script&amp;gt;.py", line 14, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from &amp;lt;parse_script&amp;gt; import &amp;lt;parse_function&amp;gt; as &amp;lt;function&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/&amp;lt;parse_script&amp;gt;.py", line 3, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from msgspec.json import encode, decode
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/msgspec/__init__.py", line 1, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from ._core import (
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr: ModuleNotFoundError: No module named 'msgspec._core'
10-31-2022 13:33:02.685 ERROR ChunkedExternProcessor [782335 searchOrchestrator] - EOF while attempting to read transport header read_size=0
10-31-2022 13:33:02.708 ERROR ChunkedExternProcessor [782335 searchOrchestrator] - Error in '&amp;lt;command&amp;gt;' command: External search command exited unexpectedly with non-zero error code 1.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 14:37:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/618998#M10827</guid>
      <dc:creator>corkster919</dc:creator>
      <dc:date>2022-11-01T14:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Python interpreter not recognizing C library module</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619013#M10828</link>
      <description>&lt;P&gt;Splunk external commands use the Splunk-provided Python interpreter and libraries.&amp;nbsp; If you need a library not supplied by Splunk then put it in the 'lib' directory of your app.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 20:09:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619013#M10828</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-10-31T20:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Python interpreter not recognizing C library module</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619027#M10829</link>
      <description>&lt;P&gt;It is. It's identified here, in the error reference I attached to the question.&lt;/P&gt;&lt;PRE&gt;File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/&amp;lt;parse_script&amp;gt;.py", line 3, in &amp;lt;module&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 00:16:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619027#M10829</guid>
      <dc:creator>corkster919</dc:creator>
      <dc:date>2022-11-01T00:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Python interpreter not recognizing C library module</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619030#M10830</link>
      <description>&lt;P&gt;As the error messages say,&amp;nbsp;msgspec._core is missing.&amp;nbsp; Add it to the lib directory.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 00:44:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619030#M10830</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-11-01T00:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Python interpreter not recognizing C library module</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619033#M10831</link>
      <description>&lt;DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;"Given I can successfully run a test script from the same &amp;lt;app&amp;gt;/bin directory as my splunk commands using the same modules...."&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;Please note that &lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; my original response, I directly highlight that I run the &lt;/SPAN&gt;&lt;SPAN&gt;EXACT&lt;/SPAN&gt; &lt;SPAN&gt;SAME&lt;/SPAN&gt; &lt;SPAN&gt;MODULE&lt;/SPAN&gt; &lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; the &lt;/SPAN&gt;&lt;SPAN&gt;EXACT&lt;/SPAN&gt; &lt;SPAN&gt;SAME&lt;/SPAN&gt; &lt;SPAN&gt;DIRECTORY&lt;/SPAN&gt;&lt;SPAN&gt; via terminal &lt;/SPAN&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;SPAN&gt; it works. It works on five separate major python release versions. I literally run a test script that does the same thing the splunk script does, just without the splunklib components&lt;/SPAN&gt;&lt;SPAN&gt;...&lt;/SPAN&gt; &lt;SPAN&gt;and&lt;/SPAN&gt;&lt;SPAN&gt; it works without issue. That implication means it&lt;/SPAN&gt;&lt;SPAN&gt;'s already there. It'&lt;/SPAN&gt;&lt;SPAN&gt;s also referenced &lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; the error message&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As it states below in the error message included in the original post, it is evident that the module is called directly from the same module directory as the __init__.py file. As is easily evident from this github page containing the python module source code,&amp;nbsp;&lt;A href="https://github.com/jcrist/msgspec/tree/main/msgspec," target="_blank" rel="noopener"&gt;https://github.com/jcrist/msgspec/tree/main/msgspec,&lt;/A&gt;&amp;nbsp;it is clear the _core.c file is downloaded simultaneously with the entire package.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/&amp;lt;parse_script&amp;gt;.py", line 3, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from msgspec.json import encode, decode
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:   File "/opt/splunk/etc/apps/&amp;lt;app&amp;gt;/bin/lib/msgspec/__init__.py", line 1, in &amp;lt;module&amp;gt;
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr:     from ._core import (
10-31-2022 13:33:02.674 ERROR ChunkedExternProcessor [782340 ChunkedExternProcessorStderrLogger] - stderr: ModuleNotFoundError: No module named 'msgspec._core'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will re-ask the same question. Again. Is there anything different with "Splunk's python interpreter" (*note I reference the specific python interpreter used by Splunk) that would prevent C libraries being used as part of the Python built-in C-extension library?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've written hundreds of custom scripts for Splunk. This is why my question is explicit with lots of context in the OP.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 02:11:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619033#M10831</guid>
      <dc:creator>corkster919</dc:creator>
      <dc:date>2022-11-01T02:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Python interpreter not recognizing C library module</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619098#M10832</link>
      <description>&lt;P&gt;I get the impression you've tested the script outside the Splunk run-time environment and it works fine.&amp;nbsp; The best way to test a Splunk script is within the Splunk environment.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;splunk cmd python foo&lt;/LI-CODE&gt;&lt;P&gt;I understand your frustration.&amp;nbsp; I'm merely pointing out that the error message says it can't find a needed module.&amp;nbsp; The fix for that is to put the module in the app.&amp;nbsp; FWIW, I use etc/&amp;lt;app&amp;gt;/lib rather than etc/&amp;lt;app&amp;gt;/bin/lib for my libraries.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 13:16:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunk-Python-interpreter-not-recognizing-C-library-module/m-p/619098#M10832</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-11-01T13:16:26Z</dc:date>
    </item>
  </channel>
</rss>

