推荐学习书目
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
oldbird
V2EX  ›  Python

第三方包 import 找不到,求教

  •  
  •   oldbird · Oct 17, 2020 · 2345 views
    This topic created in 2037 days ago, the information mentioned may be changed or developed.

    之前提过一个帖子,没解决,贴结构图,请各位朋友再帮忙看看 从 github 下载的 A.zip 包,在 conda 里,通过 pip install A.zip 安装后,site-packages 里有 A 目录,里面包括:

    init.py

    b.py

    c.py

    其中 b.py 里定义了类:

    class b():

    def foo(self):
    
    	import c
    

    在脚本中

    from A.b import b

    obj=b()

    obj.foo()

    运行时会报错 ModuleNotFoundError: No module named 'c',

    实在不知道是什么原因了,请教

    3 replies    2020-10-17 22:57:48 +08:00
    ynkkdev
        1
    ynkkdev  
       Oct 17, 2020
    import 请不要写在函数内部
    yuanlicz
        2
    yuanlicz  
       Oct 17, 2020 via Android
    from A import c 或者 from . import c 试试
    cocowind
        3
    cocowind  
       Oct 17, 2020
    import sys 打印一下导包路径,就知道了.没有想要的路径,就 append 一个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2954 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 02:35 · PVG 10:35 · LAX 19:35 · JFK 22:35
    ♥ Do have faith in what you're doing.