从pypi下载python包及其依赖项以离线安装到另一台机器的最佳方法是什么?使用pip或easy_install是否有简单的方法来做到这一点?我试图在一个没有连接到互联网的FreeBSD盒子上安装请求库。
当前回答
在可以访问internet的系统上
pip download命令允许你下载软件包而不安装它们:
pip download -r requirements.txt
(在pip的以前版本中,这被拼写为pip install——download -r requirements.txt。)
在无法访问internet的系统上
然后你可以使用
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
在不访问网络的情况下安装那些下载的模块。
其他回答
使用轮子编译包。
包:
$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)
复制tarball并安装:
$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*
注意轮二进制包不是跨机器的。
更多参考资料请访问:https://pip.pypa.io/en/stable/user_guide/#installation-bundles
从Pypi下载wheel文件(例如ddb -0.5.0-py3-none-any.whl)
pip install dlb-0.5.0-py3-none-any.whl
下载tarball,将它转移到你的FreeBSD机器并提取它,然后运行python setup.py install,你就完成了!
编辑:在此基础上,您现在还可以使用pip安装焦油球。
如果包在PYPI上,请将它及其依赖项下载到某个本地目录。 如。
$ mkdir /pypi && cd /pypi $ ls -la -rw-r--r-- 1 pavel staff 237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz -rw-r--r-- 1 pavel staff 389741 Feb 22 17:10 Jinja2-2.6.tar.gz -rw-r--r-- 1 pavel staff 70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz -rw-r--r-- 1 pavel staff 2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz -rw-r--r-- 1 pavel staff 1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz -rw-r--r-- 1 pavel staff 488207 Apr 10 18:26 boto-2.3.0.tar.gz -rw-r--r-- 1 pavel staff 490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz
有些包可能必须手动归档到类似的tarball中。当我想要某个东西的最新(不太稳定)版本时,我经常这样做。有些包不在PYPI上,所以同样适用于它们。
假设您在~/src/myapp中有一个格式正确的Python应用程序。~/src/myapp/setup.py将有install_requires列表,其中提到了你在/pypi目录下的一个或多个东西。像这样:
install_requires=[
'boto',
'Flask',
'Werkzeug',
# and so on
如果你想在运行你的应用程序的同时还能运行所有必要的依赖项,你可以这样做:
$ cd ~/src/myapp $ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi
这样,你的应用程序将直接从你的源目录执行。你可以侵入一些东西,然后重新运行应用程序而不需要重建任何东西。
如果你想将你的应用程序及其依赖项安装到当前的python环境中,你会这样做:
$ cd ~/src/myapp $ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .
在这两种情况下,如果/pypi目录中没有一个或多个依赖项,构建将失败。它不会试图从互联网上乱安装丢失的东西。
我强烈建议调用setup.py develop…和easy_install…在活动虚拟环境中,以避免污染您的全局Python环境。这是(virtualenv)应该走的路。不要在全局Python环境中安装任何东西。
If the machine that you've built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see --relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).
在可以访问internet的系统上
pip download命令允许你下载软件包而不安装它们:
pip download -r requirements.txt
(在pip的以前版本中,这被拼写为pip install——download -r requirements.txt。)
在无法访问internet的系统上
然后你可以使用
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
在不访问网络的情况下安装那些下载的模块。
推荐文章
- 如何在Flask-SQLAlchemy中按id删除记录
- 在Python中插入列表的第一个位置
- Python Pandas只合并某些列
- 如何在一行中连接两个集而不使用“|”
- 从字符串中移除前缀
- 代码结束时发出警报
- 如何在Python中按字母顺序排序字符串中的字母
- 在matplotlib中将y轴标签添加到次要y轴
- 如何消除数独方块的凹凸缺陷?
- 为什么出现这个UnboundLocalError(闭包)?
- 使用Python请求的异步请求
- 如何检查一个对象是否是python中的生成器对象?
- 如何从Python包内读取(静态)文件?
- 如何计算一个逻辑sigmoid函数在Python?
- python: SyntaxError: EOL扫描字符串文字