推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
foxyier
V2EX  ›  Python

大佬们, 请教一个问题: cannot import XXX

  •  
  •   foxyier · Feb 1, 2019 · 3434 views
    This topic created in 2682 days ago, the information mentioned may be changed or developed.

    导入自己写的模块的时候,发生不能导入的情况, 像这样: from send_email import SendMail ImportError: cannot import name 'SendMail'

    用 pycharm 是可以点进去的, 请教排查思路

    8 replies    2019-02-01 10:35:14 +08:00
    princelai
        1
    princelai  
       Feb 1, 2019
    请列出目录结构,PATHONPATH 然后再说
    foxyier
        2
    foxyier  
    OP
       Feb 1, 2019
    @princelai 执行文件和 send_email.py 文件是同一级, 我尝试 from src.libs.send_email import SendMail 也不行。
    python35
        3
    python35  
       Feb 1, 2019
    export PYTHONPATH=xxx
    arrow8899
        4
    arrow8899  
       Feb 1, 2019
    循环引用了
    13817188741
        5
    13817188741  
       Feb 1, 2019
    把文件结构列一下看看,另外是不是试试 from .send_email import SendMail
    如果是在同级目录的话.
    princelai
        6
    princelai  
       Feb 1, 2019
    首先尝试相对引用
    from .send_email import SendMail

    不行的话在每个目录加上__init__.py 文件再试

    如果还不行那就试试
    sys.path.append(“.”)


    如果还不行我怀疑你安了假 python
    foxyier
        7
    foxyier  
    OP
       Feb 1, 2019
    @princelai
    @13817188741
    @arrow8899
    @python35 多谢, 找到原因了。。确实是循环引用了。。还是第一次遇到这个坑。
    Faiz555
        8
    Faiz555  
       Feb 1, 2019
    可能是循环引用,可以在具体方法里面引用从而避免
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2928 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 06:49 · PVG 14:49 · LAX 23:49 · JFK 02:49
    ♥ Do have faith in what you're doing.