If I import the dde module after importing the win32ui module, the error generated tells me to import the win32ui module.
I get the same behaviour for builds 215 and 216
Below is a copy of a real session
C:\>c:\Python31\python.exe
Python 3.1.3 (r313:86834, Nov 27 2010, 17:20:37) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32ui
>>> import dde
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: This must be an MFC application - try loading win32ui first
>>> win32ui.GetApp()
object 'PyCWinApp' - assoc is 000000000247D150, vi=<None>, notify=0,ch/u=0/0
>>>
Looking at the source code, the import error from the dde module appears to be generated because there is no CWinApp being created
by the win32ui import, but the call to win32ui.GetApp() seems to show that there is one created.
I'll fix the message later, but I don't think I will be able to fix the behaviour.
I had the same problem with Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 and build 216.
The problem did not arise with Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 and build 214, though.
Hope it helps.
Thanks for the tip jonvspython, I could not get dde to import from the bundle that came with pythonxy 2.7.2 (build 216 of pywin32).
Dependency walker showed MSVCR90.DLL was missing from the distribution. I installed the missing DLL but dde still failed to import.
I then installed build 214 of pywin32 and it is now working. Something broke dde on the way to build 216.
I have the same problem "ImportError: This must be an MFC application - try loading win32ui first" with py2.6 / pywin 216 , when the application starts through python.exe or pythonw.exe.
The problem is not in the IDE when started through Pythonwin.exe !
When I start the IDE through python(w).exe and the script below, then the problem is there in the IDE as well.
Nothing changes when I copy&use python(w).exe next to Pythonwin.exe (and the mfc dll's there), or when I copy&use Pythonwin.exe at C:\Python : Pythonwin.exe always allows dde. python(w).exe not.
What does Pythonwin.exe do/have special? What can be done to get dde loading without Pythonwin.exe?
--
#######################################################################################
##
## Fires up the PythonWin framework via normal python(w).exe (1.5.2 tested)
##
#######################################################################################
import sys, win32ui, win32api, win32con
wc=win32con
# store original console stdout/in
constdout=sys.constdout=sys.stdout
constdin=sys.constdin=sys.stdin
def do(*paths):
import pywin.framework.startup
from pywin.framework.intpyapp import thisApp
thisApp.MakeExistingDDEConnection = lambda:None # we can have more Pythonwin's this way
app=thisApp
app.InitInstance()
try: win32api.SetConsoleTitle('PyWin Console')
except: pass
#for path in args:
# app.OpenDocumentFile(path)
app.Run()
def do2():
import pywin.framework.startup
from pywin.framework.intpyapp import thisApp
thisApp.MakeExistingDDEConnection = lambda:None
app=self=thisApp
win32ui.LoadStdProfileSettings=lambda x:None
app.InitInstance()
app.frame.ShowWindow(wc.SW_SHOW)
try: win32api.SetConsoleTitle('PyWin Console')
except: pass
#app.OpenDocumentFile("hello.py")
#app.Run()
def do3():
import thread
thread.start_new_thread( do2, () )
if __name__=='__main__' :
try: del sys.argv[0] # prevent this script from being loaded into the editor
except: pass
do()
Unlike in build 216, pywin 212's dde.pyd here seems to have the same embedded manifest as win32ui.pyd. The problem is not with win32uiole.pyd.
So I guess from 214 -> 215 a sort of bug entered into the build files regarding the dde.pyd lacking a embedded manifest.
I have seen the same behaviour as [jonvspython] on build 215 and 216. Following the latest release, I have made a comparison of build 214 and build 217 on the platforms that I have:
Windows 7 (64 bit)
- build 217
* Python 2.7.2 win32: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
* Python 2.7.2 amd64: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
* Python 3.2.2 win32: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
* Python 3.2.2 amd64: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
- build 214
* Python 2.7.2 win32: OK
* Python 2.7.2 amd64: import dde returns "No module named dde".
* Python 3.1.4 win32: OK
* Python 3.1.4 amd64: import dde returns "No module named dde".
Windows 7 (32 bit)
- build 217
* Python 2.7.2 win32: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
* Python 3.2.2 win32: "import dde" returns "ImportError: This must be an MFC application - try 'import win32ui' first", but even doing so fails
- build 214
* Python 2.7.2 win32: OK
* Python 3.1.4 win32: OK
Mark, please let me know if you need someone to test anything regarding this issue.