如何将具有模块依赖项的 Python 脚本捆绑到程序包或 .exe 文件中?

How can I bundle a Python script with module dependencies into a package or .exe file?

我的脚本有以下依赖关系

from sqlalchemy import create_engine
import pandas as pd
import numpy as np
from scipy import sparse
from sklearn import neighbors
import itertools
import math
import time
PATH_XGBOOST = "./xgboost/wrapper/"
PATH_MODEL = './models/model.model'

import sys
sys.path.insert(1,PATH_XGBOOST)
import xgboost as xgb

对于这个脚本,我想打包所有的东西,然后 运行 在另一台机器上 运行 不安装任何包或库,只安装 python。 (最好在 Linux 上打包,在 Windows 上打包 运行)有什么办法吗?据我搜索,有 pyinstaller 和 py2exe,但我无法处理它们,我猜是由于 xgboost libaray。

尝试cx_freeze

如果您想使用 distutil 脚本冻结,请按照 this 步骤