我正在尝试从终端通过PyInstaller构建一个使用statsmodels的exe文件。 exe文件由PyInstaller生成,没有错误-但是运行时出现以下错误:
ModuleNotFoundError: No module named 'statsmodels.__init__._version'
我已经尝试按照here的说明在PyInstaller的“ hooks”目录中安装statsmodels钩子,但是这不起作用。我还试图在我的Python代码中显式导入statsmodels。 init ._ version,但这也没有用。下面是我导入软件包的代码的顶部:
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.neighbors import NearestNeighbors, KNeighborsClassifier
import numpy as np
import matplotlib.pylab as plt
from sklearn.linear_model import LogisticRegression
import statsmodels.api as sm
from scipy import stats
from sklearn import datasets, neighbors
from mlxtend.plotting import plot_decision_regions
import seaborn as sns
from tqdm import tqdm
import matplotlib.ticker as mtick
from tkinter import *
from tkinter.filedialog import askopenfilename
import sklearn.utils._cython_blas
import sklearn.neighbors.typedefs
import statsmodels.tsa.statespace._filters
import statsmodels.tsa.statespace._filters._conventional
import statsmodels.tsa.statespace._filters._univariate
import statsmodels.tsa.statespace._filters._univariate_diffuse
import statsmodels.tsa.statespace._filters._inversions
import statsmodels.tsa.statespace._smoothers
import statsmodels.tsa.statespace._smoothers._conventional
import statsmodels.tsa.statespace._smoothers._univariate
import statsmodels.tsa.statespace._smoothers._univariate_diffuse
import statsmodels.tsa.statespace._smoothers._classical
import statsmodels.tsa.statespace._smoothers._alternative
import statsmodels.__init__._version
这是错误的回溯:
File "LR.py", line 9, in <module>
File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "statsmodels/api.py", line 32, in <module>
File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "statsmodels/__init__.py", line 2, in <module>
ModuleNotFoundError: No module named 'statsmodels.__init__._version'
我该怎么做才能解决此问题,以便exe文件包含statsmodels软件包并可以运行?
答案 0 :(得分:0)
statsmodels
属性访问 __version__
版本。
import statsmodels
print(statsmodels.__version__)
其中显示
v0.12.0rc0+20.g98dfc0073
在我的系统上。
您应将import statsmodels.__init__._version
替换为from statsmodels.__init__ import __version__