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
#1
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
Reply
#2
Please make sure to post full (though minimal) code for reproducing the issue, as well as the full error message.
Reply
#3
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?
Reply
#4
no it does not reside in any of the listed directories
Reply
#5
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.
Reply
#6
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  question about __repr__ in a class akbarza 4 530 Jan-12-2024, 11:22 AM
Last Post: DeaD_EyE
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 654 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 626 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 543 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  Some help with my first python class and importing ....im making a lidar program jttolleson 7 1,145 Jul-28-2023, 08:34 AM
Last Post: jttolleson
  Initiating an attribute in a class __init__: question billykid999 8 1,248 May-02-2023, 09:09 PM
Last Post: billykid999
  Newbie.... run for cover. OpenCV question Stevolution2023 2 922 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  numpy newbie question bcwilly_ca 4 1,127 Feb-10-2023, 05:55 PM
Last Post: jefsummers
  My code displays too much output when importing class from a module lil_e 4 1,103 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,267 Mar-14-2022, 11:21 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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