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

使用 clone 下来的项目放到自己项目下之后遇到 No module named 的问题

  •  
  •   erevus · Nov 18, 2015 · 3621 views
    This topic created in 3969 days ago, the information mentioned may be changed or developed.
    目录结构大概这样

    ➜ demo tree
    .
    ├── frame
    ├── lib
    ├── plugins
    │   └── sqli
    │   ├── README.md
    │   ├── __init__.py
    │   └── sqli
    │   ├── __init__.py
    │   └── lib
    │   ├── __init__.py
    │   ├── revison.py
    │   └── settings.py
    └── test.py

    test.py 里代码

    from plugins.sqli.sqli.settings import options

    #my code

    settings.py 里代码


    from lib.revison import getversion

    #code



    我运行 python test.py 时候报 No module named lib.revison
    有没有办法在不改 sqli 里的源码情况下能够引用里面的程序,因为还有很多的 plugin 。每个都改的话会蛋疼死
    4 replies  •  2015-11-18 20:48:35 +08:00
    yangtukun1412
        1
    yangtukun1412  
       Nov 18, 2015   ❤️ 1
    import sys
    sys.path.append('plugins/sqli/sqli')
    erevus
        2
    erevus  
    OP
       Nov 18, 2015
    @yangtukun1412 放到__init__.py 之后确实好使
    yangtukun1412
        3
    yangtukun1412  
       Nov 18, 2015
    @erevus 但是运行时修改 path 变量个人感觉是一种很脏的做法。
    billlee
        4
    billlee  
       Nov 18, 2015
    @yangtukun1412 这是原来的代码写得有问题, setting 里本来应该写 from .lib.revison import getversion 的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2505 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 15:09 · PVG 23:09 · LAX 08:09 · JFK 11:09
    ♥ Do have faith in what you're doing.