I am importing class from a file inside the folder source.
source --> file.py
from source.file import *
But the import does not work when I am outside conda environment. Why so?
Your Conda environment may use a different, newer, interpreter, which doesn't require __init__.py
files for a directory to be a package. To have it work outside the Conda environment, add an empty __init__.py
file inside the source
folder.
That would be the case if Conda uses Python 3.3+, while outside of Conda your Python executable defaults to a lower version, eg, Python 2 (which is really out of date now, and should not be used anymore).
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.