V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-11-18 16:13:03 +08:00 · 2605 次点击
    这是一个创建于 3072 天前的主题,其中的信息可能已经有所发展或是发生改变。
    目录结构大概这样

    ➜ 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 条回复    2015-11-18 20:48:35 +08:00
    yangtukun1412
        1
    yangtukun1412  
       2015-11-18 16:25:03 +08:00   ❤️ 1
    import sys
    sys.path.append('plugins/sqli/sqli')
    erevus
        2
    erevus  
    OP
       2015-11-18 16:32:20 +08:00
    @yangtukun1412 放到__init__.py 之后确实好使
    yangtukun1412
        3
    yangtukun1412  
       2015-11-18 16:34:43 +08:00
    @erevus 但是运行时修改 path 变量个人感觉是一种很脏的做法。
    billlee
        4
    billlee  
       2015-11-18 20:48:35 +08:00
    @yangtukun1412 这是原来的代码写得有问题, setting 里本来应该写 from .lib.revison import getversion 的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1033 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:17 · PVG 03:17 · LAX 12:17 · JFK 15:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.