PYTHONPATH作用

尝试使用命令行执行自己的一个小项目,抛出了异常

(venv) [root@node2 hui-cache-test]# python system-info-data/src/main.py
Traceback (most recent call last):
  File "system-info-data/src/main.py", line 1, in <module>
    from src.iostat.collect_op import *
ModuleNotFoundError: No module named 'src'

Google一番原来是需要配置$PYTHONPATH

export PYTHONPATH=path-to-project-directory:$PYTHONPATH

#export PYTHONPATH=/root/hui-cache-test/system-info-data:$PYTHONPATH
Published
Categorized as py

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.