Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Importing modules in embedded python

I’m trying to get module imports to work in embeddable python, but it doesn’t want to work

C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>type run_scripts\script.py
from module_test import test

print("Hello world!")
print(test())

C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>type run_scripts\module_test.py
def test():
    return "Test!"

C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>@python.exe run_scripts\script.py
Traceback (most recent call last):
  File "C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32\run_scripts\script.py", line 1, in <module>
    from module_test import test
ModuleNotFoundError: No module named 'module_test'

Why is the module not being imported? I tried changing PYTHONPATH but it didn’t help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

im not that good in python but this is should be make you understand :
The error message ModuleNotFoundError: No module named ‘module_test’ indicates that the Python interpreter is unable to find the module_test module. This can happen if the module is not located in the same directory as the script or if it is not in the Python path.

To resolve this issue, you can add the directory where the module is located to the Python path, for example:

import sys
sys.path.append(r"C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32\run_scripts")

from module_test import test

print("Hello world!")
print(test())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading