Python import failed from another folder

I am experimenting with python mainly to troubleshoot other people's code. I am trying to run the program " path\folderA\program.py".

I run the program from path\folderA

I get an error message:

ImportError: No module named fff.ggg.ppp

program.py contains the import:

from fff.ggg.ppp import mmm

In the folder "path \ folderB" there is: " path\folderB\fff\__init__.py" " path\folderB\fff\ggg"

the folder gggalso contains __init__.pyas well as the programppp.py

From reading other messages, such as Python Error "ImportError: No module named" I understand that the presence of the __init__.pyfolder makes it a "package", which makes importing from it possible - but it does not work, since I get an error message.

, , - .

- , sys.path. , ? PATH, .

, :

import sys
sys.path.append( <path to FolderB> )

( ) , - , ?

- , , - A B ?

__init__.py?

+5
2

- , - A , B ?

. - python, B. __init__.py, .

, python, , python. , . setup.py script. , folderB. python setup.py install.

, , .

+1

B sys.path, mmm A, sys.path A ( , ). __init__.py python, , __init__.py __init__.py, python . sympy python, ​​. , .

0

All Articles