Search code examples
pythonimportdirectory

How to solve error importing same library in two sibling folders?


I have an importing issue in my application which I am not able to solve.

My structure looks like the following:

mnt
 |
 |---setup.sh
 | 
 |---parentfolder
         |
         |---subfolder1
         |        |---skript1.py
         |     
         |---subfolder2
                  |---skript2.py

I'm trying to import the same library in both script's. I start skript1.py and skript2.py with calling the setup.sh:

python3 /mnt/parentfolder/subfolder1/skript1.py &
python3 /mnt/parentfolder/subfolder2/skript2.py &
sleep infinity

I'm using the exact same command inside my python scripts:

import os,sys
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(CURRENT_DIR))    
from subprocess import call

But get an import error calling the second script:

Import Error

The import is working for the first script.

Any help would be appreciated!


Solution

  • I found my mistake. Script "script2.py" in my example was named token.py in my use case. It seems that there are some issues with the filename "token", I renamed it and it is working now.