<?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 Download Install &amp;amp; import a librairy within the same python script in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4830937#M1017</link>
    <description>&lt;P&gt;Hi dear community,&lt;/P&gt;&lt;P&gt;I wondered if it was possible within the same python script to download, install and import a python librairy that is not yet part of the librairies available within the guestshell environment on a Cisco router.&lt;/P&gt;&lt;P&gt;I aim to trigger a python script (downloaded thanks to dhcp options) which requires some additionnal librairies so it can be executed properly. This script is executed by a cisco router at bootup (ZTP operation). The "cli" helps by allowing the execution of some shell command line like :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"guestshell run sudo python3 -m pip install requests"&lt;/LI-CODE&gt;&lt;P&gt;Within the same script, i would need to import the newly downloaded requests librairy.&lt;/P&gt;&lt;P&gt;Can you please advise ?&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Jerems&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2023 11:54:28 GMT</pubDate>
    <dc:creator>Jerems</dc:creator>
    <dc:date>2023-05-08T11:54:28Z</dc:date>
    <item>
      <title>Download Install &amp; import a librairy within the same python script</title>
      <link>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4830937#M1017</link>
      <description>&lt;P&gt;Hi dear community,&lt;/P&gt;&lt;P&gt;I wondered if it was possible within the same python script to download, install and import a python librairy that is not yet part of the librairies available within the guestshell environment on a Cisco router.&lt;/P&gt;&lt;P&gt;I aim to trigger a python script (downloaded thanks to dhcp options) which requires some additionnal librairies so it can be executed properly. This script is executed by a cisco router at bootup (ZTP operation). The "cli" helps by allowing the execution of some shell command line like :&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"guestshell run sudo python3 -m pip install requests"&lt;/LI-CODE&gt;&lt;P&gt;Within the same script, i would need to import the newly downloaded requests librairy.&lt;/P&gt;&lt;P&gt;Can you please advise ?&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Jerems&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 11:54:28 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4830937#M1017</guid>
      <dc:creator>Jerems</dc:creator>
      <dc:date>2023-05-08T11:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Download Install &amp; import a librairy within the same python sc</title>
      <link>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4831218#M1018</link>
      <description>&lt;P&gt;Not sure about using guestshell to install the required libraries but in the Python script you could use the following to detect and install the missing library:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import subprocess

# Check if requests library is installed
try:
    import requests
    print("Requests library is already installed.")
except ImportError:
    # Install requests library using pip
    print("Requests library is not installed. Installing now...")
    subprocess.check_call(["pip", "install", "requests"])
    print("Requests library has been installed.")&lt;/LI-CODE&gt;
&lt;P&gt;Hope that help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 16:21:35 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4831218#M1018</guid>
      <dc:creator>davidn#</dc:creator>
      <dc:date>2023-05-08T16:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Download Install &amp; import a librairy within the same python sc</title>
      <link>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4831535#M1019</link>
      <description>&lt;P&gt;Thanks a lot for your reply. It looks like at the beginning, we are also missing pip:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jerems_0-1683617478139.png" style="width: 400px;"&gt;&lt;img src="https://community.cisco.com/t5/image/serverpage/image-id/184190i313567D0B4F96A61/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jerems_0-1683617478139.png" alt="Jerems_0-1683617478139.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Jerems&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 07:31:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/download-install-amp-import-a-librairy-within-the-same-python/m-p/4831535#M1019</guid>
      <dc:creator>Jerems</dc:creator>
      <dc:date>2023-05-09T07:31:57Z</dc:date>
    </item>
  </channel>
</rss>

