Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1275

Python • import file not found on path

$
0
0
i'm dipping my toe into the world of user written import files to try and clean up my code to make it more readable. Once a function is working to my liking I plan to move it over to the import file and move on

I wrote this as the "main" program, saved as "Incl.py

Code:

import Incl_SSCEimport sysprint(sys.path)x=1y=20z=30a=adder(x,y,z)
and this as the file to be imported, saved as Incl_SSCE.py:

Code:

def adder(a,b,c):    d=a+b+c    return d

My system path is:

['/home/pi/Python code', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/pi/.local/lib/python3.9/site-packages', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.9/dist-packages']

and both files are saved to the folder /home/pi/Python Code

the error i get when I run Incl.py is:

Traceback (most recent call last):
File "/home/pi/Python code/Incl.py", line 13, in <module>
a=adder(x,y,z)
NameError: name 'adder' is not defined

Line 13 is the call to the adder function

Statistics: Posted by ras_oscar — Wed Apr 09, 2025 12:56 am



Viewing all articles
Browse latest Browse all 1275

Trending Articles