首页 > 解决方案 > Importing python modules from another directory

问题描述

I am trying to import files (python files) from another directory but it is not working as I have tried.

/pythonproject
.main.py
.__init__.py
 ->folder1
   ->.file1.py
   ->.file2.py
   ->.__init__.py
 ->folder2
   ->.functions.py
   ->.globals.py
   ->.__init__.py

I am trying to import functions.py inside of my file2.py.

I have tried

from functions import *
import functions

#file2.py
sys.path.insert(0, '/pythonproject')
import functions

标签: pythonpython-3.x

解决方案


我想你这个案子的朋友是sys.path.append


推荐阅读