I’ve created a Python 3.11.5 project in Spyder 5.4.3 containing a main.py
and functions.py
file in the same directory. For the functions in my functions.py
file, I use from sklearn.neighbors import KNeighborsClassifier
and call KNeighborsClassifier
in myFunc following this other question.
Python: how to write a function which depends on external modules
When I run my main.py
file (from functions import myFunc
without duplicate imports) and call myFunc in main.py
, I get an error saying name 'KNeighborsClassifier' is not defined
. I want to have a separate functions.py
with known import dependencies that I can send to others.
The only solution currently is to run functions.py
before running main.py
. I have tried using * import, using/omitting .py from functions.py
.
sqp97 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1