简体   繁体   English

Python包导入错误

[英]Python package import error

I'm trying to package my modules, but I can't seem to get it working. 我正在尝试打包我的模块,但我似乎无法让它工作。

My directory tree is something like the following: 我的目录树类似于以下内容:

snappy/
    __init__.py
    main/
        __init__.py
        main.py
        config.py
        ...
    ...      

and the code I'm using is 我正在使用的代码是

from snappy.main.config import *

I'm getting the error: 我收到错误:

ImportError: No module named snappy.main.config

Any ideas what's going wrong? 有什么想法会出错吗? This is using Python 2.5 on Ubuntu 8.10. 这是在Ubuntu 8.10上使用Python 2.5。

Thanks in advance for your help. 在此先感谢您的帮助。

Is the parent directory of snappy in sys.path ? 是的父目录snappysys.path If it's not, that's the only thing I can think of that would be causing your error. 如果不是,那就是我唯一能想到的就是导致你的错误。

It depends on where your script using the import resides and your system PYTHONPATH. 这取决于使用导入的脚本所在的位置和系统PYTHONPATH。 Basically, to have that import working you should run your script (the one having the import) in the parent directory of snappy or your script should change sys.path to include it. 基本上,要使该导入工作,您应该在snappy的父目录中运行您的脚本(具有导入的脚本),或者您的脚本应该更改sys.path以包含它。

./alex ./alex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM