Strange difference when running a Python file directly or packed with py2exe -
I create an application that, when running on Windows, Problem: My code controls the I am using this function if it is on Windows (or not), then there is a way to program it to know. When running the .py file directly, everything is the same. When running the packaged .py file via Py2exe, the generated .exe file assumes that this is a non-Windows system and the Question 1: What could be the reason for this? Question 2: Is there a better way to detect Windows / non-Windows environments? I think I read about the method which I am using here somewhere on stack overflow but I can not remember where exactly it is. This code is (the beginning of this, actually enough to generate directories) and the next code I am using for py2exe build. The Vista system that I am using for soup is 64 bit, Python 2.7.6 and PY2Ex6.6.9, both 32 bit (as well as wxPython 2.8 12, 32bit , Unicode, if it matters here). Edit: I tried Dahih's solution and so I came to know what is the difference between my code, but the reason I do not mean the difference generated by Py2exe -. In the exe version the program now closes with "importError: no module named shell", so it is now clear why the program omits the original So now a third question comes: Question 3: What should I do about the "import error: designated a module" error? This does not happen if the .py program runs directly from the command line. edit2: I think I got an answer for Q3, then try to understand the potential fix explained later edit3: The solution given on py2exe.org, solved the problem on all the questions. your second question , Use % USERPROFILE% \ AppData \ roaming Directories for different types of files - otherwise, on Linux, only the
$ HOME directory should be used: and
% USERPROFILE% \ documents
shell.SHGetFolderPath () function differently, depending on whether I run the .py file directly or py2exe Is packed by.
% USERPROFILE% directory for both codes is directly
$ HOME < The data files and user files that are used as / code>, except for this difference, the rest of the program runs fine (each version is in accordance with its different paths successfully).
attempt: statement.
#! / Usr / bin / Env python appname = "AA AP name" Eppath = "Name of PP path" Import OS import then define # OS specific path # Create the application directory if not already exists # Edit - Change the code # Was: try: # Next line is new: if os.name == 'nt': "" "if window" "# edit - Py2exe packed version, next line" importError: no module named " From win32com.shell import shellcon, shell homedir_appdata = shell.SHGetFolderPath (0, shellcon.CSIDL_APPDATA, 0, 0) homedir_documents = shell.SHGetFolderPath (0, shellcon.CSIDL_P ERSONAL, 0, 0) # Edit - The code was changed #: except the import error: # Next line is new: Other: "" "If non-windows" "" homedir = os.p Ath.expanduser ("~" ) homedir_appdata = homedir homedir_documents = homedir apppath = "." + apppath.lower () appdata_path = os.path.join (homedir_appdata, apppath) document_path = os.path.join (homedir_documents, apppath) match = re.search (r ' Exclude os.path.isdir (documents_path): except for osrror os.makedirs (documents_path) except "osrror": osmaths (appdata_path) excluding OSError: "osrror" excluding osrror. Try: raise # specified file path and file name config_filename = appname + ".ini" config_filename_wpath = os.path.join (appdata_path, config_filename) user_filename = appname + ".csv" user_filename_wpath = specify os.path.join (documents_path, user_filename) # etc. Import distatils.core import setup from py2exe import system, OS sys.argv.append ('py2exe') setup (option = {' Py2exe ': {' dll_excludes': ['w9xpopen.exe'], 'dist_dir': 'dist',}}, name = "test", windows = [{{script}: "test.py"},}, Zip file = none, description = "test file",)
import os if os.name == 'nt': #do Windows stuff here elif os.name == 'posix': Linux accessories here - note OS X is shown as 'posx'. For your first question, py2exe could do some weird things, i had problems with py2app before but i do not have a windows box to play with, on which to see shell strangeity.
Comments
Post a Comment