我有以下文件夹结构.
application/app/folder/file.py
我想从另一个驻留的Python文件中的file.py中导入一些函数
application/app2/some_folder/some_file.py
我试过了
from application.app.folder.file import func_name
和其他一些尝试,但到目前为止我无法正确导入.我怎样才能做到这一点?
我怎样才能使用PYTHONPATH?当我尝试在路径中运行脚本时,找不到该文件.当我cd到包含脚本的目录时,脚本运行.那么PYTHONPATH有什么用呢?
$ echo $PYTHONPATH
:/home/randy/lib/python
$ tree -L 1 '/home/randy/lib/python'
/home/randy/lib/python
??? gbmx_html.py
??? gbmx.py
??? __init__.py
??? __pycache__
??? scripts
??? yesno.py
$ python gbmx.py -h
python: can't open file 'gbmx.py': [Errno 2] No such file or directory
$ cd '/home/randy/lib/python'
Run Code Online (Sandbox Code Playgroud)
cd到文件目录后运行..
$ python gbmx.py -h
usage: gbmx.py [-h] [-b]
Run Code Online (Sandbox Code Playgroud)
为什么我不能使用PYTHONPATH?