我有以下文件夹布局:
my_folder/
my_subfolder/
__init__.py
main.py
import_1.py
import_2.py
带有文件:
# main.py
from my_subfolder import import_1
import_1.call_import_2(3)
和
# import_1.py
from my_subfolder import import_2
def call_import_2(n):
import_2.print_hello_world_n_times(n)
和
# import_2.py
def print_hello_world_n_times(n):
for i in range(n):
print('hello world')
Now the thing is, if I run main.py
in pycharm, it works fine. However, if I run it from the command line python my_subfolder/main.py
or python main.py
(depending which folder I am in), it doesn't work! The git bash also cannot get it to work. I get the error:
ModuleNotFoundError no module named 'my_subfolder'
有谁知道是什么原因导致pycharm和命令行之间出现此差异?