Python Forum
newbie question....importing a created class - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: newbie question....importing a created class (/thread-30050.html)



newbie question....importing a created class - ridgerunnersjw - Oct-01-2020

Hello all....
I've created a class in a directory using Python. I go to my command line to import and I get an error 'ModuleNotFoundError'.

Can someone tell me where I edit Python so that when it runs it will have a pointer to my location and be able to import files?

Thanks


RE: newbie question....importing a created class - micseydel - Oct-01-2020

Please make sure to post full (though minimal) code for reproducing the issue, as well as the full error message.


RE: newbie question....importing a created class - deanhystad - Oct-01-2020

Sounds like your class is not somewhere Python can find it. Start python and type:
import sys
print('\n'.join(sys.path))
Does the module you are trying to import reside in or in a subdirectory of one of the listed directories?


RE: newbie question....importing a created class - ridgerunnersjw - Oct-01-2020

no it does not reside in any of the listed directories


RE: newbie question....importing a created class - deanhystad - Oct-01-2020

You can move the module to be in the same directory you are working in, you can move your module so it is in a subdirectory of one of the directories in sys.path, or you can add the directory for the module to sys.path.


RE: newbie question....importing a created class - ridgerunnersjw - Oct-01-2020

I prefer not to move the files....my files exist at /home/pi/my_Python/Radar

the python path is:

Output:
>>> print('\n'.join(sys.path)) /usr/lib/python37.zip /usr/lib/python3.7 /usr/lib/python3.7/lib-dynload /usr/local/lib/python3.7/dist-packages /usr/lib/python3/dist-packages
I have included
#! /usr/bin/python
at the front end of the module containing the class

Would like to add the directory to the python path so that I can just use import?