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.
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
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 468 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Question from complete python's newbie Davicom 3 1,381 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  Importing issues with base class for inheritance riccardoob 5 1,789 May-19-2021, 05:18 PM
Last Post: snippsat
  Newbie question about running Python via GUI on OSX ejwjohn 8 2,041 Feb-05-2021, 03:20 PM
Last Post: Larz60+
  super newbie question: escape character tsavoSG 3 1,500 Jan-13-2021, 04:31 AM
Last Post: tsavoSG
  Dumb newbie question JonEdward 5 1,909 Jul-22-2020, 10:06 PM
Last Post: snippsat
  Class question robdineen 7 1,811 May-30-2020, 05:44 AM
Last Post: Calli
  importing CSV file into a OOP Class table using Python faruk61 1 1,987 Apr-15-2020, 12:00 PM
Last Post: faruk61
  Newbie: Help with variable selection in a class Slack86 5 1,616 Apr-07-2020, 08:41 PM
Last Post: jefsummers
  Question about naming variables in class methods sShadowSerpent 1 1,229 Mar-25-2020, 04:51 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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