I have mypackage
folder with empty __init__.py
and two modules compute.py
and config.py
. Being in the folder that contains mypackage
and main.py
, I run python main.py
which has from mypackage.compute import myfunction
and inside the compute.py
there is from config import *
. The folder structure is below:
main.py
mypackage
__init__.py
compute.py (contains myfunction)
config.py
Now, when I run python main.py
everything works perfectly, whereas if I run python3 main.py
, I get:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from mypackage.compute import myfunction
File "/home/myself/Downloads/mypackage/compute.py", line 1, in <module>
from config import *
ImportError: No module named 'config'
Not quite sure what could be wrong here?
Python 3.x has changed import resolution. You must now specify a full relative import if you want to perform a relative import.
from .config import *
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.