I had a file called mem.py
in my directory and from another script I have imported:
from mem import get_val
Then I decided to move mem.py
into funcs
subdirectory. To make it visible to my script, from which I import, I have added into it:
import sys
sys.path.append('/home/myname/src/funcs/')
However, python cannot import mem
anymore! It is interesting that it still can import other stuff from other files located in funcs
.
I assume that python somehow memorises that mem.py
in current directory and keep searching there and did not find it (because it is moved to funcs
).
I want to __pycache__
subdirectory and found mem.pyc
in there and thought that it was a problem. So, I have deleted it. However, it did not help, I still cannot import form mem.py
. So, what am I doing wrong?
ADDED
I guess the problem was resolved when I have changes the order of imports. My interpretation is as follow:
- In my first (not working example) the first import was from
mem
. Python remembers that mem is in the current directory, tries to find it there, does not succeed and crashes. - If I change the order of imports. Python sees a new library and starts to search it. It finds it in the 'funcs' sub-directory and creates the corresponding *.pyc file. This step kind of force Python to search other stuff (also the old one) in the
funcs
subdirectory.