doc-exports/docs/fg/umn/functiongraph_03_0343.html
Chen, Junjie dac566cf2f FG UMN 20230725 version
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-04-03 10:30:56 +00:00

55 lines
6.1 KiB
HTML

<a name="functiongraph_03_0343"></a><a name="functiongraph_03_0343"></a>
<h1 class="topictitle1">How Do I Create Function Dependencies?</h1>
<div id="body1578636921482"><p id="functiongraph_03_0343__p1328185911261"><strong id="functiongraph_03_0343__b181151512317">You are advised to create function dependencies in EulerOS.</strong> If other OSs are used, an error may occur due to underlying dependent libraries. For example, the dynamic link library cannot be found.</p>
<div class="note" id="functiongraph_03_0343__note14541146896"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_03_0343__p12014204329">If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.</p>
</div></div>
<div class="section" id="functiongraph_03_0343__section2788105014255"><h4 class="sectiontitle">Creating a Dependency for a Python Function</h4><p id="functiongraph_03_0343__p5429134511271">Ensure that the Python version of the packaging environment is the same as that of the function. For Python 2.7, Python 2.7.12 or later is recommended. For Python 3.6, Python 3.6.3 or later is recommended.</p>
<p id="functiongraph_03_0343__p1439713124284">To install the PyMySQL dependency for a Python 2.7 function in the local <strong id="functiongraph_03_0343__b250742441715">/tmp/pymysql</strong> directory, run the following command:</p>
<pre class="screen" id="functiongraph_03_0343__screen76938158298">pip install PyMySQL --root /tmp/pymysql</pre>
<p id="functiongraph_03_0343__p567422072818">After the command is successfully executed, go to the <strong id="functiongraph_03_0343__b1175517131843">/tmp/pymysql</strong> directory:</p>
<pre class="screen" id="functiongraph_03_0343__screen152535410296">cd /tmp/pymysql/</pre>
<p id="functiongraph_03_0343__p13929173017285">Go to the <strong id="functiongraph_03_0343__b132254295569">site-packages</strong> directory (generally, <strong id="functiongraph_03_0343__b5986125885612">usr/lib64/python2.7/site-packages/</strong>) and then run the following command:</p>
<pre class="screen" id="functiongraph_03_0343__screen1696862618307">zip -rq pymysql.zip *</pre>
<p id="functiongraph_03_0343__p478854972710">The required dependency is generated.</p>
<div class="note" id="functiongraph_03_0343__note196394284492"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_03_0343__p79932437502">To install the local wheel installation package, run the following command:</p>
<pre class="screen" id="functiongraph_03_0343__screen4513201316518">pip install piexif-1.1.0b0-py2.py3-none-any.whl --root /tmp/piexif
//Replace <strong id="functiongraph_03_0343__b7620196196">piexif-1.1.0b0-py2.py3-none-any.whl</strong> with the actual installation package name.</pre>
</div></div>
</div>
<div class="section" id="functiongraph_03_0343__section18693175462512"><h4 class="sectiontitle">Creating a Dependency for a Node.js Function</h4><p id="functiongraph_03_0343__p179881059193012">Ensure that the corresponding Node.js version has been installed in the environment.</p>
<p id="functiongraph_03_0343__p5477114963114">To install the MySQL dependency for a Node.js 8.10 function, run the following command:</p>
<pre class="screen" id="functiongraph_03_0343__screen432583110338">npm install mysql --save</pre>
<p id="functiongraph_03_0343__p198017773216">The <strong id="functiongraph_03_0343__b105361419155912">node_modules</strong> folder is generated under the current directory.</p>
<ul id="functiongraph_03_0343__ul9671814193419"><li id="functiongraph_03_0343__li167114145341">Linux OS<p id="functiongraph_03_0343__p490624183319"><a name="functiongraph_03_0343__li167114145341"></a><a name="li167114145341"></a>Run the following command to generate a ZIP package.</p>
<pre class="screen" id="functiongraph_03_0343__screen183711635278">zip -rq mysql-node8.10.zip node_modules</pre>
<p id="functiongraph_03_0343__p8849911183216">The required dependency is generated.</p>
</li></ul>
<ul id="functiongraph_03_0343__ul23961046113416"><li id="functiongraph_03_0343__li4396114653417">Windows OS<p id="functiongraph_03_0343__p28821753217"><a name="functiongraph_03_0343__li4396114653417"></a><a name="li4396114653417"></a>Compress <strong id="functiongraph_03_0343__b1083017356539">node_modules</strong> into a ZIP file.</p>
</li></ul>
<p id="functiongraph_03_0343__p213613143212">To install multiple dependencies, create a <strong id="functiongraph_03_0343__b1898018373292">package.json</strong> file first. For example, enter the following content into the <strong id="functiongraph_03_0343__b103179398302">package.json</strong> file and then run the following command:</p>
<pre class="codeblock" id="functiongraph_03_0343__codeblock18415124714328">{
"name": "test",
"version": "1.0.0",
"dependencies": {
"redis": "~2.8.0",
"mysql": "~2.17.1"
}
}</pre>
<pre class="screen" id="functiongraph_03_0343__screen1522003713518">npm install --save</pre>
<div class="note" id="functiongraph_03_0343__note1476915419337"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="functiongraph_03_0343__p276912403316">Do not run the <strong id="functiongraph_03_0343__b6143611171610">CNPM</strong> command to generate Node.js dependencies.</p>
</div></div>
<p id="functiongraph_03_0343__p929493533112">Compress <strong id="functiongraph_03_0343__b10911975317">node_modules</strong> into a ZIP package. This generates a dependency that contains both MySQL and Redis.</p>
<p id="functiongraph_03_0343__p8294135133115">For other Node.js versions, you can create dependencies in the way stated above.</p>
</div>
<div class="section" id="functiongraph_03_0343__section485582613141"><h4 class="sectiontitle">Creating a Dependency for a Java Function</h4><p id="functiongraph_03_0343__p5577101412157">When you compile a function using Java, dependencies need to be compiled locally. </p>
<p id="functiongraph_03_0343__p136191245429"></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_03_0883.html">Dependency Management FAQs</a></div>
</div>
</div>