I have the following relevant libraries and files in my project:
Project_Library
data
some_folder
sub_folder1
script1.py
sub_folder2
script2.py
scripts
__init__.py
lib_a.py
The code in script1.py
works perfectly and looks a bit like this:
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, "C:/Project_Library/scripts") #
from lib_a import *
#Some more irrelevant code here
The code in script2.py
doesn't work, Python claims ImportError: No Module named lib_a
while I actually copied and pasted the heading of script1.py
:
# -*- coding: utf-8 -*-
import sys
sys.path.insert(0, "C:/Project_Library/scripts") #
print sys.path #looks good
from lib_a import * #Crashes here
#again, more code
What possible reason can cause this?
EDIT:
A very interesting note. If I try to run script2.py
after copying the file into sub_folder1
without changing a thing, it DOES work. Then why doesn't it work in sub_folder2
?
EDIT2:
I did get it to work, for some reason just creating a new file and copying and pasting the file's content into it just worked miraculously! I still kept the original file with the original file name, as it still DOESN'T work on it, very interesting. I wonder what the source of the problem could possibly be