Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果我使用cx\u Freeze和python将py文件转换为exe,我的脚本将关闭_Python_Python 2.7_Cx Freeze - Fatal编程技术网

如果我使用cx\u Freeze和python将py文件转换为exe,我的脚本将关闭

如果我使用cx\u Freeze和python将py文件转换为exe,我的脚本将关闭,python,python-2.7,cx-freeze,Python,Python 2.7,Cx Freeze,欢迎大家,, 我使用的是Python2.7和cx_Freeze,当我得到一个执行文件并尝试运行它时,它会打开一个cmd一秒钟,然后直接关闭。 主脚本的代码是: import time import xlrd import xlsxwriter from openpyxl import Workbook import openpyxl import datetime from datetime import datetime from lxml import etree import smtpli

欢迎大家,, 我使用的是Python2.7和cx_Freeze,当我得到一个执行文件并尝试运行它时,它会打开一个cmd一秒钟,然后直接关闭。 主脚本的代码是:

import time
import xlrd
import xlsxwriter
from openpyxl import Workbook
import openpyxl
import datetime
from datetime import datetime
from lxml import etree
import smtplib
import logging
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from apscheduler.schedulers.blocking import BlockingScheduler
import six
import packaging
import packaging.version
import packaging.specifiers

times = time.strftime ( "%A %d. %B %Y. %H %M" )
print times
driver = webdriver.Firefox ( )
mailList = ['mails']
driver.get ( "url" )
username = driver.find_element_by_css_selector ( '#user' )
username.send_keys ( 'user' )
password = driver.find_element_by_css_selector ( '#txtpassword' )
password.send_keys ( 'pass' + Keys.ENTER )
try:
    driver.get ( "url" )
except:
        print 'we are trying to load it!!'
xc = input ('press any key to exit')
def some_job ( ):
        driver.get ( "url" )
        username = driver.find_element_by_css_selector ( '#user' )
        username.send_keys ( 'user' )
        password = driver.find_element_by_css_selector ( '#txtpassword' )
        password.send_keys ( 'txtpassword' + Keys.ENTER )
        #
        try:
            driver.get ( "url" )
        except:
                print 'we are trying to load it!!'
        global mailList

        # sending mail 023-02
        content = ' script is reloaded'
        mail = smtplib.SMTP ( 'smtp.gmail.com', 587 )
        mail.ehlo ( )
        mail.starttls ( )
        mail.login ( 'mail@gmail.com', '******')
        i = 0
        for i in range ( 0, 5, 1 ):
                # global times
                mail.sendmail ( 'mail@gmail.com', mailList[i], content + ' ' + times )
                time.sleep ( 5 )
                mail.close ( )


try:
    scheduler = BlockingScheduler ( )
    time.sleep ( 10 )
    logging.basicConfig ( )
    scheduler.add_job ( some_job, 'interval', minutes=60 )
    scheduler.start ( )
except:
    print 'one error'
执行脚本的代码为:

 import sys
from cx_Freeze import setup, Executable

build_exe_options = {"packages": ["os", "lxml", "gzip"], "excludes": ["tkinter"]}

base = 'Console'

setup(  name = "filename",
    version = "0.1",
    description = "desc",
    options = {"build_exe": build_exe_options},
    executables = [Executable("filename.py", base=base)])
我尝试使用for循环和input退出,但没有任何结果,有时它会显示错误

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "myfile.py", line 13, in <module>
  File "C:\Python27\lib\site-packages\apscheduler\__init__.py", line 2, in <module>
    release = __import__('pkg_resources').get_distribution('APScheduler').version.split('-')[0]
  File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 70, in <module>
    from pkg_resources.extern import appdirs
  File "C:\Python27\lib\site-packages\pkg_resources\extern\__init__.py", line 61, in load_module
    "distribution.".format(**locals())
ImportError: The 'appdirs' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
回溯(最近一次呼叫最后一次):
文件“C:\Python27\lib\site packages\cx\u Freeze\initscripts\\uuuuu startup\uuuu.py”,第14行,正在运行
module.run()
文件“C:\Python27\lib\site packages\cx\u Freeze\initscripts\Console.py”,第26行,正在运行
执行官(代码、指令)
文件“myfile.py”,第13行,在
文件“C:\Python27\lib\site packages\apscheduler\\uuuu init\uuuu.py”,第2行,在
release=uu import('pkg_resources').get_发行版('APScheduler').version.split('-')[0]
文件“C:\Python27\lib\site packages\pkg\u resources\\uuuu init\uuuu.py”,第70行,在
从pkg_resources.extern导入appdirs
文件“C:\Python27\lib\site packages\pkg\u resources\extern\\uuuuu init\uuuuu.py”,第61行,在加载模块中
“分发。”.format(**locals())
ImportError:需要“appdirs”包;通常情况下,这与此软件包捆绑在一起,因此如果您收到此警告,请咨询您的发行版的包装商。

,敬请告知。

您是否检查了appdirs软件包?如果不尝试
pip,则显示appdirs
并验证输出。这是调试它的一个良好开端。我认为问题在于你的pkg_资源被捆绑到了其他东西中。我也找不到一个很好的解决方案,所以我最终改用pyinstaller。