使用cx_Freeze抛出错误

时间:2018-01-19 08:15:47

标签: python executable cx-freeze

我使用cx_Freeze为我的一个预测脚本创建了.exe文件,在用于创建.exe文件的setup.py文件下面

from cx_Freeze import setup, Executable
import os

import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')



options = {
    'build_exe': {
        'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
         ],
    },
}

additional_mods = ['numpy.core._methods', 'numpy.lib.format']


setup(name = "Prediction" ,
      version = "0.1" ,
      description = "" ,
      options = {'build_exe': {'includes': additional_mods}},
      executables = [Executable("Prediction.py")])

但是当我试图执行它时,我得到了以下错误

ImportError:无法导入名称' shortest_path'

使用另一种方法pyinstaller创建的.exe文件工作正常,但我不确定为什么使用cx_Freeze创建的.exe无效。

我试图检查此错误但无法获得解决方案,任何人都可以帮助我。

按要求分享预测脚本

import os
import pandas as pd       
from bs4 import BeautifulSoup
import re
from nltk.corpus import stopwords # Import the stop word list
from nltk.tokenize import word_tokenize
import pickle
from nltk.stem import WordNetLemmatizer

# Read the test data
test = pd.read_csv("Future.csv",encoding='cp1252')

##wordnet_lemmatizer
wordnet_lemmatizer = WordNetLemmatizer()

def Description_to_words(raw_Description):
    Description_text = BeautifulSoup(raw_Description).get_text() 
    letters_only = re.sub("[^a-zA-Z]", " ", Description_text)
    words = word_tokenize(letters_only.lower())    
    stops = set(stopwords.words("english")) 
    meaningful_words = [w for w in words if not w in stops]
    return( " ".join(wordnet_lemmatizer.lemmatize(w) for w in meaningful_words))

num_Descriptions = len(test["message"])
clean_test_Descriptions = [] 

print("Cleaning and parsing the test mail message...\n")
for i in range(0,num_Descriptions):
    if( (i+1) % 1000 == 0 ):
        print("Description %d of %d\n" % (i+1, num_Descriptions))
    clean_Description = Description_to_words( test["message"][i] )
    clean_test_Descriptions.append( clean_Description )



vect=pickle.load(open("vector.pickel","rb"))
test_data_features = vect.transform(clean_test_Descriptions)

test_data_features = test_data_features.toarray()

# Use the 
svc=pickle.load(open("classifier-svc.pickel","rb"))
resultsvc= svc.predict(test_data_features)
resultsvcP= svc.predict_proba(test_data_features)

resultsvcPD = pd.DataFrame(resultsvcP)
max_per_row = resultsvcPD.max(axis=1)

output = pd.DataFrame( data={"label":test["label"], "PredictedLabel":resultsvc, "message":test["message"],"MaxProbability":max_per_row} )

output.to_csv( "Result.csv")

0 个答案:

没有答案