The question is old and has been asked many times, yet I'm not able import my own module. What am I missing?
python3 --version
rm --recursive --force /tmp/mypython
mkdir --parents --verbose /tmp/mypython/test
cd /tmp/mypython/test/
touch /tmp/mypython/__init__.py
printf "def myfunction():
print('foo')" > /tmp/mypython/mymodule.py
printf "import mymodule
mymodule.myfunction()" > /tmp/mypython/test/mytest.py
tree /tmp/mypython/
python3 mytest.py
Returns:
Python 3.9.1
mkdir: created directory '/tmp/mypython'
mkdir: created directory '/tmp/mypython/test'
/tmp/mypython/
├── __init__.py
├── mymodule.py
└── test
└── mytest.py
1 directory, 3 files
Traceback (most recent call last):
File "/tmp/mypython/test/mytest.py", line 1, in <module>
import mymodule
ModuleNotFoundError: No module named 'mymodule'