Python Forum
newbie question....importing a created class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
newbie question....importing a created class
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?

Please make sure to post full (though minimal) code for reproducing the issue, as well as the full error message.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Sounds like your class is not somewhere Python can find it. Start python and type:
import sys
Does the module you are trying to import reside in or in a subdirectory of one of the listed directories?
no it does not reside in any of the listed directories
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.
I prefer not to move the files exist at /home/pi/my_Python/Radar

the python path is:

>>> print('\n'.join(sys.path)) /usr/lib/ /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?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Question from complete python's newbie Davicom 3 727 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  Importing issues with base class for inheritance riccardoob 5 801 May-19-2021, 05:18 PM
Last Post: snippsat
  Newbie question about running Python via GUI on OSX ejwjohn 8 1,275 Feb-05-2021, 03:20 PM
Last Post: Larz60+
  super newbie question: escape character tsavoSG 3 906 Jan-13-2021, 04:31 AM
Last Post: tsavoSG
  Dumb newbie question JonEdward 5 1,321 Jul-22-2020, 10:06 PM
Last Post: snippsat
  Class question robdineen 7 1,324 May-30-2020, 05:44 AM
Last Post: Calli
  importing CSV file into a OOP Class table using Python faruk61 1 1,271 Apr-15-2020, 12:00 PM
Last Post: faruk61
  Newbie: Help with variable selection in a class Slack86 5 1,087 Apr-07-2020, 08:41 PM
Last Post: jefsummers
  Question about naming variables in class methods sShadowSerpent 1 889 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  class question jrauden 1 703 Feb-16-2020, 10:14 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020