0

I am trying to run a python script located at a different directory using a soft link. Here is what I have done -

This is the main script calling other scripts located in all_tests folder -

import os
import sys
import time

modules_path = os.path.dirname(os.path.realpath(sys.argv[0])) + "/all_tests"
sys.path.append(modules_path)

import getScriptsReady         #located in all_tests
import create_my_test_1        #located in all_tests

# get current paths
saved_path = os.getcwd()    
realpath   = os.path.dirname(os.path.realpath(sys.argv[0]))

print("Current Directory: " + saved_path)
print("Path to main.py: ", realpath)
print("Path to Sub-Script Directory: ", modules_path)

Here is the file hierarchy I am using -

.
├──template
│   ├──refr
│   │   ├──bin
│   │   │   ├──main.py
│   │   │   ├──all_tests
│   │   │   │    ├── getScriptsReady.py
│   │   │   │    ├── create_my_tests.py
    |
    ├──sim
         ├──tests

I am trying to run from tests directory using - ../refr/bin/main.py but am getting the error -

File "../refr/bin/main.py", line 8, in <module>
    import getScriptsReady
ModuleNotFoundError: No module named 'getScriptsReady'
  • What you have should work. Do the paths you've printed look right (assuming you move the `import`s to after the `print`s? – Tim Roberts Jun 23 '22 at 20:08
  • See also [how to import a directory as python module](https://stackoverflow.com/questions/44786278/how-to-import-a-directory-as-python-module). – hc_dev Jun 23 '22 at 20:14
  • @TimRoberts All these files are present in a Cliosoft database. I have to check out the main.py file to run it. I want to just run it normally without checking it out. – Katrina Marrie Jun 23 '22 at 20:44

0 Answers0