如题,现在准备用 python 写一个 kafka 的 producer 造测试数据,但是公司服务器没联外网, pip install pykafka 显然是不可能能的。公司服务器是 linux 的,然后我的开发环境是 Mac OS,打包成 exe 八成没戏,仲么办?
![]() | 1 bwangel 2020-04-02 14:32:41 +08:00 用 Docker 。 > docker help export Usage: docker export [OPTIONS] CONTAINER Export a container's filesystem as a tar archive Options: -o, --output string Write to a file, instead of STDOUT > docker help import Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]] Import the contents from a tarball to create a filesystem image Options: -c, --change list Apply Dockerfile instruction to the created image -m, --message string Set commit message for imported image --platform string Set platform if server is multi-platform capable |
![]() | 2 ipwx 2020-04-02 14:32:44 +08:00 anaconda |
![]() | 3 dapang1221 2020-04-02 14:34:50 +08:00 venv 啊 |
![]() | 6 wangyzj 2020-04-02 14:37:55 +08:00 pyinstaller |
![]() | 7 wuwukai007 2020-04-02 14:40:22 +08:00 via Android 下载 whl 的包离线安装 |
8 ShuoHui 2020-04-02 14:40:22 +08:00 via iPhone 我前几天问过差不多的问题 |
9 nifury 2020-04-02 14:40:54 +08:00 https://stackoverflow.com/questions/11091623/how-to-install-packages-offline 第二个回复可以只下载不安装,然后再转移到测试机上 或者直接下载 wheel 文件安装? |
10 sakura1 OP venv 啥的好像是 python3 才有的吧,服务器里就一个 linux 自带的 python2,我继续撸 java 吧 |
![]() | 11 Trim21 2020-04-02 14:41:05 +08:00 找台有外网的 linux 服务器或者虚拟机包 exe 比较省劲,又要跨平台又要离线安装的需求太罕见了 |
12 deljuven 2020-04-02 14:44:12 +08:00 容器镜像或者虚拟机镜像,venv 也可以,但是如果跨平台的话就有问题 |
![]() | 13 bwangel 2020-04-02 14:45:16 +08:00 https://github.com/Parsely/pykafka/blob/master/pykafka/rdkafka/_rd_kafkamodule.c 1. pykafka 中是有 C 代码的,你在 Mac 上创建的 venv 放到 Linux 上是不能使用的,必须本地也在 Linux 中构建。 2. pykafka 依赖一个 C 库,https://github.com/edenhill/librdkafka,所以你先要在 公司服务器上装好这个库。 所以 Docker 真是最简单的办法了。 |
![]() | 14 raysmond 2020-04-02 14:48:12 +08:00 用 wheel 打包所有依赖包 pip wheel -r requirements.txt -w wheels tar czf delphinus-wheels.tar.gz wheels/ |
![]() | 15 bwangel 2020-04-02 14:48:44 +08:00 另外,如果你的项目不复杂的话,还有一个建议就是用 Go 重写。 在交叉编译好了以后,直接把可执行文件扔到公司服务器上运行,不需要任何的依赖。 |
![]() | 17 ipwx 2020-04-02 14:59:54 +08:00 |
![]() | 18 ClericPy 2020-04-02 15:14:43 +08:00 用 shiv 打包成 pyz, 但是还是离不开 Python 解释器, 这种问题问的挺多的, V2EX 上就不止回复 2 次了..... |
![]() | 19 jingcoco 2020-04-02 19:54:47 +08:00 via Android 。。。我曾经试过让我的电脑代理服务器上网。。。。。 |
20 lance86 2020-04-02 20:33:40 +08:00 回 5 楼,就算是你写 java,你也要在服务器上装 jre 不是? docker 的话有离线安装包,镜像可以导出成文件然后离线还原,就能运行了。 |