I have a python script that receives an image from the Internet, downloads it, sets it as the desktop background and updates after a minute. Most likely, the cx_Freeze problem does not include the os module, since the same code with absolute paths works fine. My code also works fine until it goes through freezing. It works before it is frozen, when I load the console, start from IDLE or double-click on it. Whenever I run a frozen file, I get an error (if I use setup.py or cxfreeze file.py :
C:\Python33\Scripts>C:\Python33\Scripts\dist\desktopchanger.exe Traceback (most recent call last): File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2 7, in <module> exec(code, m.__dict__) File "C:\Python33\desktopchanger.pyw", line 7, in <module> dir = path.dirname(__file__) NameError: name '__file__' is not defined
My code
import pythoncom from urllib import request from win32com.shell import shell, shellcon from time import sleep from os import path dir = path.dirname(__file__)
setup.py
from cx_Freeze import setup, Executable exe=Executable( script="desktop_changer_with_url2.py", base="Win32Gui", icon="icon.ico" ) includes = ["os","urllib","time","pythoncom","win32com.shell"] setup( name = "Heindl Webcam als Desktop" , version = "1", description = "eowjbadpoaäbaaplabipösdbjosdobsaboösac bjcaähpdaöbökabidsidsöds.", executables = [exe], )
source share