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

怎么在使用 wsgi 时导入自定义的模块

  •  
  •   zeyexe · Dec 22, 2011 · 5466 views
    This topic created in 5391 days ago, the information mentioned may be changed or developed.
    我在 apache + wsgi 中要导入一个自己写的模块,把模块放到 c:\python\lib 目录下,import mymodule 可以正常工作,但是把它放到工程目录 d:\project\ 下则出现 500 Internal Server Error。如果我想把模块放到工程目录下,而又不想把工程目录加到系统路径,请问应该怎么写 import?
    4 replies  •  1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       Dec 22, 2011
    把想要的路径加入sys.path试试
    zeyexe
        2
    zeyexe  
    OP
       Dec 22, 2011
    @keakon 这样可以用,只是代码变成了
    import sys
    sys.path.append('D:/project/')
    import module
    好像不太整齐
    ry_wang
        3
    ry_wang  
       Jan 9, 2012
    如果用的mod_wsgi的话,请查询WSGIPythonPath参数用法
    如果用的uWSGI的话,请查询pythonpath参数用法
    lepture
        4
    lepture  
       Jan 9, 2012
    python2.7+ 建议使用 site
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2775 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:23 · PVG 21:23 · LAX 06:23 · JFK 09:23
    ♥ Do have faith in what you're doing.