0

Welcome all, I'm using Python 2.7 and cx_Freeze and when I got executed file and when I try to run it, it open a cmd for a sec and closed directly. the code of the main script is :

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'

code of the executing script is :

 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)])

I tried to use for loop and input to exit but without any results and sometimes it shows that error

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.

, kindly advise me.

  • Have you checked the `appdirs package`? If don't try `pip show appdirs` and verify the output. It's a good start for debug it. – brunormoreira May 29 '17 at 21:09
  • I think the problem is your pkg_resources are bundled into something else. I couldn't find a good solution for this either, so I ended up using pyinstaller instead. – Gardener85 May 30 '17 at 18:09

0 Answers0