Forum Discussion

BD_Geoactive's avatar
BD_Geoactive
Contributor
1 hour ago

ModuleNotFoundError. Python Runtime error only on other machine but not mine

I have a a project suite containing multiple projects.

In one of those project (see prerequisite project in the image) i have written several python scripts.

so, in another project, for e.g.; 'Z_ModuleNotFoundTest' project, i have added the same script from pre-requisite project y using the 'add existing item' option.

My intention is that i can access/open a menu in our app by using the OpenMenu script and re-use it for different project.

Long short story. I have used this without issue and able to open menus using the OpenMenu script in any given projects, so does my colleague when they use the same branch/test complete file.

BUT! recently, somehow... the OpenMenu script finding an error and it says;

 Python runtime error.

ModuleNotFoundError: No module named 'tc_loader'


The strangest thing about this issue, is that I cannot reproduce it on my machine, but my colleague recently got into this trouble in his one.

This is the codes overview for OpenMenu.py: (error occurred on line 17)

from tc import *

# ==========================
# Imports
# If you want to access some functions from another file, in another project(s), you must add the lines below.
# ==========================
import sys # used to modify the Python module search path
import os # for working with filesystem paths
import re # for regular expressions

# Defining folder paths - named to reflect the logical grouping of modules.
BASE_SCRIPT_PATH = r"C:\REPOS\TestComplete_IP\Prerequisites\Script"

if BASE_SCRIPT_PATH not in sys.path:
    sys.path.append(BASE_SCRIPT_PATH)
    
import tc_loader

MODULE_NAMES = [
    "IpLogsMain",
    "MenuDictionaries",
    "SubMenusDatabaseDict",
    "SubMenusWellDict",
      "SubMenusMulti_WellOptionsDict", #drop down sub-menu in Well      
      "SubMenusDeleteParameterSetsDict" #drop down sub-menu in Well
]

modules = tc_loader.load_modules(BASE_SCRIPT_PATH, MODULE_NAMES)

# =========== Function > Open a module according to user input ===============
#  > rule: calling a module 'Create New Well' by the following method:"Well|Create New Well"
#  > The menu level separated by a pipe '|' and any menu items must match what you see in IP
#  > ...
# ==========================
def openModule(moduleName):

and this is the tc_loader.py overview:

import os
import sys
from typing import Dict, Optional
# ===========================================
# Path Management
# ===========================================
def safe_add_path(path: str) -> None:
    # Safely adds a folder to sys.path (if exists and not already added).
    if not os.path.exists(path):
        print(f"WARNING: Path does NOT exist → {path}")
        return

    if path not in sys.path:
        sys.path.append(path)
        print(f"Added to sys.path: {path}")
    else:
        print(f"Path already in sys.path: {path}")

# ===========================================
# Module Import
# ===========================================
def safe_import(module_name: str) -> Optional:
    # attempt to import a module and handle error if occurrring.
    try:
        module = __import__(module_name)
        print(f"Imported: {module_name}")
        return module
    except Exception as e:
        print(f"Failed to import {module_name}: {e}")
        return None

def load_modules(base_path: str, module_names: list) -> Dict[str, Optional[object]]:
    # Add path once, then load all requested modules safely.    
    # Returns:
    #    Dictionary of module_name → module_object_or_None
    safe_add_path(base_path)

    loaded = {}
    for name in module_names:
        loaded[name] = safe_import(name)

    return loaded

To say it one more time, Its working on my machine, but not a colleague of mine...

few things i have to mention...

  • his machine had update from IT and had python removed
  • its reinstalled to 3.13.12
  • Remove Test Complete app 15.81 and re-installed

Is there a disconnection of python setup i have missed? as mine is working and the other dont?

Any help much appreciated.

regards,

BD

No RepliesBe the first to reply