I am trying to use Cython to wrap a C++ class. Basically I follow the example at this page.
I'm using Windows7 64-bit, Python 2.7.4 64-bit, MinGW 4.3.3 (32/64bit), and the SDK has been set to x64 mode.
In this case, I successfully build the .pyd file. I tried to import it with following code:
import sys
sys.path.append("C:\\Rectangle")
import rect
The first two lines work well. When I input the third line, it gave following message:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import rect
ImportError: DLL load failed: %1 is not a valid Win32 application.
I compiled the extension in 64bit mode, and every piece of software I used is at least compatible with 64bit. How could such error happened?
May I know how can I work around this?
Many thanks! :-)
I ended up switching everything to 32bit (python, wxPython, etc.), and everything is fine now.
So, I would really recommend that you use "file rect.pyd" command to determine if your module is really 64bit.
Related
I would like to use the following Python package, which requires ncurses: https://pypi.python.org/pypi/blessings
I have the Windows version of Anaconda Python installed, and designated as my Python distribution.
I have also have a Cygwin installation. When I run python -i within the provided Cygwin terminal, Anaconda Python starts up -- great!
If I then try import blessings, I'll get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "A:\anaconda\lib\site-packages\blessings\__init__.py", line 5, in <module>
import curses
File "A:\anaconda\lib\curses\__init__.py", line 15, in <module>
from _curses import *
ImportError: No module named _curses
Alright, so what's happening is that Anaconda Python is understandably not picking up Cygwin's curses.
Now, does it even make sense to try and somehow make Anaconda aware of ncurses, only within the context of usage in a Cygwin terminal? I suspect it isn't, and that I am missing something conceptually?
You won't be able to use Cygwin Python's curses module with CPython unfortunately. Modules for the two Pythons are incompatible for the following reasons (and more):
Windows Python directly calls the Win32 API (via either the Visual Studio 2008, 2010 or 2015 C-Runtimes) while Cygwin Python links to the Cygwin POSIX API which is layered on top of the Visual Studio 6.0 C-Runtime. Mixing different C-Runtimes in a single process is a very bad idea: http://siomsystems.com/mixing-visual-studio-versions/, never mind further abstracted through a POSIX API.
Regardless of the C-Runtime differences, Cygwin implements the LP64 model while Windows implements the LLP64 model which would make the 64-bit size of long different between each, so some structures could be differently sized. They would likely be anyway due to #ifdefs in the code.
Is there any reason you can't use colorama?
The documentation for blessings suggests that should work.
I have a python script that works fine on my computer (Python 2.7 32 bit installed). It has the following imports :
import mechanize
from bs4 import BeautifulSoup
from Tkinter import *
import json
import webbrowser
I wanted to distribute this to others so I found that we can create exe files using py2exe. I wrote a script like this:
from distutils.core import setup
import py2exe
setup(console=['notification.py'],
options = {'py2exe' : {
'packages' : ['bs4', 'mechanize','Tkinter', 'json', 'webbrowser']
}})
This works fine on my computer but when I run it on Windows XP, I get this error -
Traceback (most recent call last):
File "notification.py", line 3, in
File "Tkinter.pyc", line 38, in
File "FixTk.pyc", line 65, in
File "_tkinter.pyc", line 12, in
File "_tkinter.pyc", line 10, in __load
ImportError: DLL load failed: %1 is not a valid Win32 application.
I tried searching other threads but found none that has the same problem. So please help me fix this issue.
Maybe Tinkiter is a 64 bit version GUI, while Windows XP version you run it is 32bit.
Check it out and tell us if that's the case.
Reason I assume this is the line:
ImportError: DLL load failed: %1 is not a valid Win32 application.
combined with the fact that Tinkiter is 64 bit.
Python can be 32 bit. Works on both Operating Systems, 32 and 64 bit ones.
But Tinkiter is a GUI, something different than the language.
So Including a 64bit add-on, into a 32bit application... can cause some trouble. :)
Suggestion:
You can start by making the app work in console interface if possible.
Then you can use another GUI that can run in 32 bit.
For instance, you can get a 32bit version of THIS
Edit: Added a suggeston.
Well, I had installed both versions of Python 32 bit and 64 bit in my machine. When I was making it a stand alone probably some dlls were copied from the wrong library. So I completely uninstalled both versions and then installed 32 bit and it worked fine.
I am trying to work with OpenCV in Python 2.7, however when I simply import cv2, I am getting this error:
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "cv2.py", line 9, in <module>
from VideoCapturePlayer import *
ImportError: No module named VideoCapturePlayer
I figured that VideoCapturePlayer may be in pygame or pycam, but when I import both, no problems arise.
I have searched my folders and the web for VideoCapturePlayer. My folders do not contain it, and the internet provided a .py file, but I do not know where I should put it. Any help is greatly appreciated, thank you.
Edit: I guess I should include that I am on Windows 7 64-bit
The link you provided is for downloading the entire OpenCV project, including all the libraries and bindings for C++, Java, etc. etc. For the Python bindings, it's much easier to visit my favorite module site on the Internet, Christoph Gohlke's Python Extension Packages for Windows repository. Find the OpenCV section, pick AMD64 or Win32, pick py2.7 or py2.6, and wait a bit for the self-extracting archive to download. Run it, hit OK for all the prompts, and you should be all set. Fire up IDLE or run python from the command line, and running import cv2 should give you no response at all - indicating that everything got set up just fine.
Good luck!
How is it possible to run import win32api successfully on a 64bit maya version 2008?
The following error occurs:
Error: No module named win32api
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named win32api
I need to get mouse cursor position in python so that I can place window exactly in that position. Is there any other way to get it?
Best regards,
kNish
Maya uses its own Python installation. You need to add the path where pywin32 is installed by one way or another ... you can create a .pth file in
C:\Program
Files\Autodesk\Maya2009\Python\Lib\site-packages\
Also, like Adam pointed out, make sure you have the 64 bit pywin32 installed.
Here's an article talking about this subject:
http://www.rtrowbridge.com/blog/2008/11/27/maya-python-import-scripts/
Edit:
Yeah indeed I think they don't provide PyWin32 for Python25 x64:
Available for AMD64 versions of
Windows for Python 2.6 and later
(support for Python 2.5 is just too
hard, sorry). Lots of help from
Roger, Steve Yin and Sidnei da
Silva.
http://sourceforge.net/project/shownotes.php?release_id=603349
I want to run this library on Python 2.4 in Windows XP.
I installed the pygpgme-0.8.1.win32.exe file but got this:
>>> from pyme import core
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python24\Lib\site-packages\pyme\core.py", line 22, in ?
import pygpgme
File "C:\Python24\Lib\site-packages\pyme\pygpgme.py", line 7, in ?
import _pygpgme
ImportError: DLL load failed: The specified module could not be found.
And then this pop up comes up
---------------------------
python.exe - Unable To Locate Component
---------------------------
This application has failed to start because python25.dll was not found. Re-installing the application may fix this problem.
---------------------------
OK
Do I need to "compile" it for Python 2.4? How do I do that?
While the pygpgme project does not clearly document it, it's clear from the error message you got that their .win32.exe was indeed compiled for Python 2.5.
To compile their code for Python 2.4 (assuming they support that release!), download their sources, unpack them, open a command window, cd to the directory you unpacked their sources in, and run python setup.py install. This will probably not work unless you have the right Microsoft C compiler installed (MSVC 6.0 if I recall correctly).
It's no doubt going to be much less trouble to download, install and use Python 2.5 for Windows (it can perfectly well coexist with your current 2.4, no need to remove that). Is that a problem?