<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sergio Luiz Custodio Rezende</title>
    <description>The latest articles on DEV Community by Sergio Luiz Custodio Rezende (@sergio_luizcustodioreze).</description>
    <link>https://dev.to/sergio_luizcustodioreze</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3265847%2Fd735ef5d-a15d-4f59-b9bd-3bf30bbb3035.png</url>
      <title>DEV Community: Sergio Luiz Custodio Rezende</title>
      <link>https://dev.to/sergio_luizcustodioreze</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sergio_luizcustodioreze"/>
    <language>en</language>
    <item>
      <title>Erro ao chamar uma biblioteca</title>
      <dc:creator>Sergio Luiz Custodio Rezende</dc:creator>
      <pubDate>Sat, 14 Jun 2025 22:11:49 +0000</pubDate>
      <link>https://dev.to/sergio_luizcustodioreze/erro-ao-chamar-uma-biblioteca-4gbk</link>
      <guid>https://dev.to/sergio_luizcustodioreze/erro-ao-chamar-uma-biblioteca-4gbk</guid>
      <description>&lt;p&gt;Hello&lt;/p&gt;

&lt;p&gt;I am in a dilemma where when calling a program that uses a library that is in another directory structure.&lt;br&gt;
It gives an error if I do not declare the full path of the project.&lt;br&gt;
In item 2 I show the normal program, but it gives an error when executed. In item 5 I show declaring the path, and it works when executed&lt;br&gt;
I will describe the entire flow:&lt;/p&gt;

&lt;p&gt;1- directory structure:&lt;br&gt;
src/conta.py&lt;br&gt;
tools/calcula.py&lt;/p&gt;

&lt;p&gt;2- in the code conta.py:&lt;br&gt;
    import random&lt;br&gt;
    from tools.calcular import Calculator #&amp;lt;-error if you don't declare the path&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = Calculator.sum(4,2)
print(result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  --------------ERROR
&lt;/h1&gt;

&lt;p&gt;3- in the code calcula.py&lt;br&gt;
        class Calculator:&lt;br&gt;
        def &lt;strong&gt;init&lt;/strong&gt;(self):&lt;br&gt;
        pass&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    def sum(self, a, b):
    return a + b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;4- error via vscode:&lt;br&gt;
        """&lt;br&gt;
        PS D:\portifolio\teste2&amp;gt; &amp;amp; d:/portifolio/teste2/.venv/Scripts/python.exe d:/portifolio/teste2/src/conta.py&lt;br&gt;
        Traceback (most recent call last):&lt;br&gt;
        File "d:\portifolio\teste2\src\conta.py", line 15, in &lt;br&gt;
        from tools.calcular import Calculator&lt;br&gt;
        ModuleNotFoundError: No module named 'tools'&lt;br&gt;
        """&lt;/p&gt;

&lt;h1&gt;
  
  
  -------------IT WORKS
&lt;/h1&gt;

&lt;p&gt;5- if you put the full path it works&lt;/p&gt;

&lt;p&gt;in the code conta.py:&lt;br&gt;
        import random&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    #------------------if you declare the path
    import sys
    import os
    project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    if project_root not in sys.path:
    sys.path.insert(0, project_root)
    #------------------

    from tools.calcular import Calculator &amp;lt;-error when running via vscode

    result = Calculator.sum(4,2)
    print(f'SUM RESULT: {result}')

    result:
    SUM RESULT: 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;QUESTION:&lt;br&gt;
    Has anyone had this problem, or know how to solve it?&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
