<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sys.path on ErrorVault — Developer Error Code Dictionary</title><link>https://errorvault.dev/tags/sys.path/</link><description>Recent content in Sys.path on ErrorVault — Developer Error Code Dictionary</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 18 Sep 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://errorvault.dev/tags/sys.path/feed.xml" rel="self" type="application/rss+xml"/><item><title>Fix ModuleNotFoundError: Resolve Python import failures for missing modules</title><link>https://errorvault.dev/python/python-modulenotfounderror-missing-module/</link><pubDate>Wed, 18 Sep 2024 00:00:00 +0000</pubDate><guid>https://errorvault.dev/python/python-modulenotfounderror-missing-module/</guid><description>&lt;h2 id="1-symptoms">1. Symptoms&lt;/h2>
&lt;h2 id="the-modulenotfounderror-is-a-subclass-of-importerror-raised-when-python-cannot-locate-a-specified-module-during-import-common-manifestations-include">The &lt;code>ModuleNotFoundError&lt;/code> is a subclass of &lt;code>ImportError&lt;/code> raised when Python cannot locate a specified module during import. Common manifestations include:&lt;/h2>
&lt;p>Traceback (most recent call last):
File &amp;ldquo;script.py&amp;rdquo;, line 1, in &lt;!-- raw HTML omitted -->
import nonexistent_module
ModuleNotFoundError: No module named &amp;rsquo;nonexistent_module'&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Symptoms vary by context:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#ff79c6">**&lt;/span>Fresh Python install&lt;span style="color:#ff79c6">**&lt;/span>: Errors on standard library modules &lt;span style="color:#ff79c6">if&lt;/span> paths are misconfigured (rare)&lt;span style="color:#ff79c6">.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#ff79c6">**&lt;/span>Third&lt;span style="color:#ff79c6">-&lt;/span>party packages&lt;span style="color:#ff79c6">**&lt;/span>: Fails after `pip install` &lt;span style="color:#ff79c6">if&lt;/span> using wrong interpreter&lt;span style="color:#ff79c6">.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#ff79c6">**&lt;/span>IDE&lt;span style="color:#ff79c6">-&lt;/span>specific&lt;span style="color:#ff79c6">**&lt;/span>: VS Code &lt;span style="color:#ff79c6">or&lt;/span> PyCharm shows red squiggles &lt;span style="color:#ff79c6">or&lt;/span> fails to resolve imports&lt;span style="color:#ff79c6">.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#ff79c6">**&lt;/span>Virtual environments&lt;span style="color:#ff79c6">**&lt;/span>: Import succeeds &lt;span style="color:#ff79c6">in&lt;/span> one env but fails &lt;span style="color:#ff79c6">in&lt;/span> base Python&lt;span style="color:#ff79c6">.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">-&lt;/span> &lt;span style="color:#ff79c6">**&lt;/span>Subprocess calls&lt;span style="color:#ff79c6">**&lt;/span>: `subprocess&lt;span style="color:#ff79c6">.&lt;/span>run` with scripts importing unavailable modules&lt;span style="color:#ff79c6">.&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Full example &lt;span style="color:#ff79c6">in&lt;/span> a script:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>```python
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#6272a4"># example.py&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>import requests &lt;span style="color:#6272a4"># Assume not installed&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8be9fd;font-style:italic">print&lt;/span>(&lt;span style="color:#f1fa8c">&amp;#34;Hello&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Running &lt;code>python example.py&lt;/code> yields:&lt;/p></description></item></channel></rss>