Python Forum
Importing Custom Modules in Python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing Custom Modules in Python 3
#1
I'm working on updating my scripts from Python 2 to 3, and I'm running into trouble with importing my custom modules. My __init__.py works fine when I run it directly, but when I run a script from outside the folder, it throws an error that a sub-module file can't be found. It seems to be looking in the higher folder for the files; why is that?
Reply
#2
If not modifying the top __init__.py file to lift sub modules,most import the the whole path in the package(file tree).
I almost always lift sub modules and bind package together in in top __init__.py.
This make import easier for user of package and not like the example under example
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas

Also from Python 3.3+ supports Implicit Namespace Packages that allows to create a package without an __init__.py file.
This however only applies to empty __init__.py files,so if lifting sub modules still need top __init__.py.
Look at this post
See that import my_makehtml and can use the whole package using my_makehtml.
Also see this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  confusion on importing modules carter187 4 343 Mar-03-2024, 08:11 PM
Last Post: snippsat
  I want to create custom charts in Python. js1152410 1 501 Nov-13-2023, 05:45 PM
Last Post: gulshan212
  How to see the date of installation of python modules. newbieAuggie2019 4 1,466 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  python standard way of importing library mg24 1 872 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  Importing modules from different folders Tomli 3 1,428 Jun-26-2022, 10:44 AM
Last Post: snippsat
  Python modules for accessing the configuration of relevant paths Imago 1 1,324 May-07-2022, 07:28 PM
Last Post: Larz60+
  Python modules to extract data from a graph? bigmit37 5 22,193 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Where to add own python modules in WinPython? HinterhaeltigesSchlaengelchen 1 2,241 Jan-21-2021, 07:45 PM
Last Post: snippsat
  Including modules in Python using sys.path.append JoeDainton123 1 2,849 Aug-24-2020, 04:51 AM
Last Post: millpond
  importing a list of numbers into python script barrypyth 8 4,434 Aug-22-2020, 09:10 PM
Last Post: barrypyth

Forum Jump:

User Panel Messages

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