Compiling python-mcrypt in win32? - python

Um, I'm stumped and really stuck (+_+) here after googling many sites. I'm using mingw32-gcc.exe from Dev-c++ compiler and currently following instructions from this site.
Every time I try here's the result:
C:\Python26>python c:\python26\python-mcrypt-1.1\setup.py install
running install
running build
running build_ext
error: don't know how to compile C/C++ code on platform 'nt' with 'mingw32-gcc.exe' compiler
I've edited the distuils.cfg file in my c:\python26\lib\distuils\distuils.cfg with this parameter
[build]
compiler = mingw32-gcc.exe
Any ideas would be appreciated!

You installed python outside of a compilation environment valids one include cygwin or mingw32 (wich is used by Dev-C++).
To use the command-line mode, you need to find the your compiler installation and find bat script which launch the shell with the proper parameters (This is needed for bith cygwin and mingw).
The alternative is to use Microsft solution for that problem.

Related

Problems finding vcvarsall.bat when using distutils

So this problem started out when I tried building an extension with Cython using the following setup.py script.
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [
Extension("program1",["program1.pyx"],),])
When I try build it using:
python setup.py build I get the following error:
error: Unable to find vcvarsall.bat
I am using the Microsoft Visual C++ Compiler Package for Python 2.7. After a bit a research, some other SO questions led me to believe that my PATH variables weren't properly set.
I set it as follows:
VS90COMNTOOLS=C:\...\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\;
which is where my vcvarsall.bat file is located. This didn't solve my problem as I was still getting the same error about vcvarsall.bat.
I know there's already a bunch of posts about this particular error already but I still haven't found a solution.
I found this discussion specifically about my problem however I don't understand the following steps:
1) Enter MSVC for Python command prompt (how do I do this?)
2) SET DISTUTILS_USE_SDK=1
3) SET MSSdk=1
4) python.exe setup.py ...
Finally: further down in the discussion Steve proposes to replace the
from distutils.core import setup
with
from setuptools import setup
This worked! However now I have a problem, whenever I try to run something that uses distutils setup instead of setuptools, it raises the same "cannot find vcvarsall.bat" problem.
For example, I tried using the IPython magic command
%%cython_inline
I've been at this for a couple days now and all I want is to properly fix the issue for good, it's been very frustrating.
A patch was made recently which is supposed to fix the issue with finding vcvarsall.bat. You can see that here. Do I just run the script/functions inside it? It didn't seem to change anything in my distutils\msvc9compiler.py file.
I hope someone can point me in the right direction here.
There has been further discussions on the python bug tracker here. It's not an ideal fix but Mark Lawrence suggests a rather simple hack that works. Here's what was suggested:
My work around for this was to edit the distutils msvc9compiler.py file.
I commented out the line vcvarsall = find_vcvarsall(version) in the function
query_vcvarsall and hard coded vcvarsall = r'C:\Program Files\Microsoft
Visual Studio 9.0\VC\vcvarsall.bat'. This assumes that you've got a copy of
Visual C++!:) HTH.
The msvc9compiler.py file is located in C:\Python27\Lib\distutils (or somewhere else if you installed Python in a different location than the default). The only change I made is pointing the vcvarsall.bat file to my specific MSVC compiler.
In my case, since I used the Microsoft Visual C++ Compiler Package for Python 2.7 to compile Python, I changed the variable as follows:
vcvarsall =
r'C:\Users\..\AppData\Local\Programs\Common\Microsoft\Visual C++ for
Python\9.0\vcvarsall.bat' #where .. is my user account name
From this message on the Python bug tracker
The correct solution to this issue now is to install the Microsoft supplied "Visual C++ Compiler for Python 2.7" package (available as a free download from MSDN). That has all the components needed to build 32 and 64-bit extensions. Your setup.py needs to use setuptools (as there is a setuptools extension to recognise this compiler package) but otherwise the process should be seamless.

ImportError: DLL load failed: Invalid access to memory location. Using aubio in Python

For a schoolproject I need to make use of the aubio library. However, I have a problem compiling it for Windows.
I downloaded the latest source from his git (0.4.0 alpha). Then I compiled it using Cygwin, using the --with-target-platform=win32 to cross-compile it for Windows. It uses waf by the way.
This works without any errors.
Next step is copying the compiled file (libaubio.dll.a) to MinGW library folder. Then I want to compile the Python wrapper for the module, but it shows up the ld.exe cannot find -laubio error. Renaming the libaubio.dll.a to libaubio.a resolves this and compiling succeeds succesfully.
Installing it into the Python folder works perfectly too. But here starts the problem. When trying to import aubio, I get this error: ImportError: DLL load failed: Invalid access to memory location.
I have no clue on how to solve this problem. Can anybody help? Or explain the error to me?
Thanks in advance!
Xander
PS. It compiles perfectly on both OSX and Ubuntu.
Well, this may not be the right solution for you, just a hint. ImportError: DLL load failed: Invalid access to memory location. I encountered the same error when trying to make my own extension of Python programmed in C. Platform: Windows 32bits.
It was a real pain because this error appeared randomly in interactive as well as in non-interactive mode in all Python environments (Spyder, Notebook, plain console...). I compiled my code using MinGW and Python's distutils (command python setup.py install). The compilation gave no warnings or errors and produced pyd file to the correct directory. But when trying to import this module import example pro my Python code it irregularly crashed (usually only one out of five attempts to import the module succeeded).
Strange was that on another computer it worked just fine... Well, finally I found workaround - I downloaded a newer version of MinGW (before I had used the version that comes packed in Qt SDK distribution) and compiled the module again. Then it worked with no more crashes. However I did not find any systematic solution or explanation. So I might have something to do with the compiler (maybe absence of its DLLs? I do not know exactly) that was used to generate the pyd file.

unable to install graph-tool in windows 7

I'd like to use graph-tool on windows 7, but I'm having trouble installing it.
All the requirements listed here are successfully installed. Python 2.7 is installed in C:\python27. Boost 1.49.0 was successfully compiled with mingw, installed in C:\boost and the BOOST_ROOT environment variable is pointing to it. Boost is compiled in debug and release mode and both static and dynamic.
Invoking configure from within MSyS leads to the following error.
configure: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================
Calling configure LDFLAGS="-LC:/python27/libs" fixed this error, but lead to the following error
checking for boostlib >= 1.38.0... configure: error: We could not detect the boo
st libraries (version 1.38 or higher). If you have a staged boost library (still
not installed) please specify $BOOST_ROOT in your environment and do not give a
PATH to --with-boost option. If you are sure you have boost installed, then ch
eck your version number looking in <boost/version.hpp>. See http://randspringer.
de/boost for more documentation.
This is weird, since BOOST_ROOT is clearly defined (checked it with printenv command).
The next command I tried was configure --with-boost="C:/boost" LDFLAGS="-LC:/python27/libs"
checking for boostlib >= 1.38.0... yes
checking whether the Boost::Python library is available... no
configure: error: No usable boost::python found
Alright it detects boost, but It can't find boost::python. Due to its size I'm unable to post the config.log on stackoverflow but you can find it here.
I'm really confused right now and would appreciate any help.
I have zero experience with compiling graph-tool (or anything else) for windows, but the following part of your config.log stands out:
configure:17224: checking whether the Boost::Python library is available
configure:17254: g++ -c -Wall -ftemplate-depth-150 -Wno-deprecated -Wno-unknown-pragmas -O99 -fvisibility=default -fvisibility-inlines-hidden -Wno-unknown-pragmas -Ic:\python27\include conftest.cpp >&5
conftest.cpp:32:36: fatal error: boost/python/module.hpp: No such file or directory
compilation terminated.
Note how the boost path you passed is not being used! Try to pass CXXFLAGS="-IC:\boost\include" to configure as well.
May be something like this would help:
./configure --prefix=/usr/
for windows path is different, try it yourself.

Compiling Python Extension On Windows With Cygwin

I have been having a terrible time trying to compile a python extension - hopefully someone can help.
I initially tried executing 'python.exe setup.py build' but received the error: 'Python was built Visual Studio 2003; extensions must be built with a compiler that can generate compatible binaries...".
So I then downloaded Cygwin, and have tried sending the switch '-c mingw32'. A few lines were written into the console - then I get the error message: command 'gcc' failed: Permission denied.
I was initially using the Visual Studio 2010 Command Line to do this, but tried with bash and got the same result.
I have spent a considerable amount of time researching the issue, and it appears Cygwin uses symlinks for gcc and g++, and windows doesn't understand how to handle this.
How exactly can I force setup.py to use gcc-3.exe instead of the gcc.exe symlink?
I know it's inelegant, but you can rename the symlink and copy gcc-3.exe to gcc.exe. That worked for me when I used Cygwin's gcc. You might want to switch to the mingw64-i686 (or mingw64-x86_64) package to get gcc 4.5.3, or just install MinGW-w64 separately for compiling under Windows.
Also, you can permanently configure distuilts in PythonXX\Lib\distutils\distutils.cfg:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
[build_clib]
compiler = mingw32

Extension Crashing Python on Import?

I have a python extension that is built and installed through distutils (using mingw on windows). However on import of this module the interpreter crashes. Is there anyway to debug and figure out why it crashes?
I did look around online and couldn't find anything specific, or any examples.
EDIT
Sorry i am trying to compile for python 2.5.4 (we need 2.5.4, since we use arcgis geoprocessor library):
http://effbot.org/media/downloads/ftpparse-1.1-20021124.zip
On windows, i define crash as: "Python.exe has encountered a problem and needs to close"
I'll try debugging with GDB
EDIT 2
For what ever reason, doing a
setup.py clean
For the package and doing:
setup.py install
fixed all the problems. :psyduck:
Simply running the following may give you a clue about what call is causing the issue without having to break out a debugger. But if you just get a silent crash you're going to have to put on your detective hat as per Xavier's answer.
strace python -v -c "import faultylib"
I suppose using gdb see http://oldwiki.mingw.org/index.php/gdb

Categories