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
eightqueen
V2EX  ›  Python

python 如何根据环境打包?

  •  
  •   eightqueen · 2015-10-15 15:08:21 +08:00 · 3611 次点击
    这是一个创建于 3114 天前的主题,其中的信息可能已经有所发展或是发生改变。
    java 的 maven 很容易做这个事情,写好配置文件,打包的时候指定环境名称(测试、开发、线上)就可以了。
    6 条回复    2017-04-10 15:49:34 +08:00
    hahasong
        1
    hahasong  
       2015-10-15 15:10:50 +08:00
    venv freez 一个 requirents 清单
    kamushin
        2
    kamushin  
       2015-10-15 15:29:58 +08:00
    用 pip wheel+requirements. 线上一般不能访问 pip 仓库的时候, wheel 就有用了
    curiouslfq
        3
    curiouslfq  
       2015-10-15 21:04:57 +08:00
    tox
    tinyproxy
        4
    tinyproxy  
       2015-10-15 23:11:08 +08:00 via iPhone
    docker
    owendev
        5
    owendev  
       2015-10-16 16:35:31 +08:00
    可以使用这两条命令:
    pip freeze > requirements.txt ## 到处依赖到文件
    pip install -r requirements.txt ## 读取依赖文件,安装依赖
    JhOOOn
        6
    JhOOOn  
       2017-04-10 15:49:34 +08:00
    有时候, 需要部署 Python 应用的服务器没有网络连接, 这时候, 你就要把整个 Python 应用做成离线安装包.
    借助 wheel, 很容易就可以实现.

    首先, 你的开发机器上要安装 wheel:

    pip install wheel
    接下来, 下载依赖包的 wheel 文件:

    pip wheel -r requirements.txt
    默认情况下, 上述命令会下载 requirements.txt 中每个包的 wheel 包到当前目录的 wheelhouse 文件夹, 包括依赖的依赖.
    现在你可以把这个 wheelhouse 文件夹打包到你的安装包中. 在你的安装脚本中执行:

    pip install --use-wheel --no-index --find-links=wheelhouse -r requirements.txt
    就可以实现离线安装了. 当然, 还要考虑 pip 以及 wheel 自身的安装.

    参考: http://guoqiao.me/post/2015/1212-pip-install-offline-via-wheels
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1166 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:29 · PVG 02:29 · LAX 11:29 · JFK 14:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.