What's the best way to call python scripts from Visual Basic 2005?
I've got an application written in visual basic 2005 that needs to call into a library written in python. The library requires python 2.6. I'm using the python C API to access the python library from the visual basic code (private declare function blah lib "python26.dll" etc). I'm doing it this way because I want to pull values out of python after the python library does its thing. Unfortunately, I get an error about the C run-time:
"R6034: An application has made an attempt to load the C runtime library incorrectly."
I think it's a conflict between MSVCR80.dll (the 2005 runtime) and MSVCR90.dll (the 2008 runtime that python 26 uses). A simple stub program written with Visual C++ 2005 that does essentially the same thing as the visual basic code also throws that error. If I compile with Visual C++ 2008 it runs fine.
So what do I do about it? I can't move away from VB, or even move to the 2008 version. I've already recompiled python 2.6 using MSVC 2005, and that wasn't enough. Do I have to track down all of the python packages the library uses and recompile those too? It seems like there must be an easier way.
Related
I'm trying to do simple OCR .Net program using C# in Windows 10 without using Visual Studio. What i did is using ironpython + python script. I've managed to pass bitmap data into a python script and output it. However, when i tried to process it using OpenCV and Tesseract-OCR, ironpython fail to import opencv and pytesseract ( this is just a guess ) and further research about ironpython made me realize it doesn't support both of it.
Currently, i'm trying to switch to Cpython.
My questions is:
Does Cpython support import of OpenCV and Pytesseract for python file?
Or is there a more elegant and simple method for OCR using C#, with the help of OpenCV and Tesseract-OCR in Windows 10 without using Visual Studio?
Does Cpython support import of OpenCV and Pytesseract for python file
I have no idea.
Or is there a more elegant and simple method for OCR using C#, with the help of OpenCV and Tesseract-OCR in Windows 10 without using Visual Studio?
You can use OpenCV directly in c#, either with p/Invoke or with a wrapper like emguCV. The situation with Tesseract seem to be similar. I fail to see what Python would add, except added complexity.
It is really unclear what you mean with "without using Visual Studio". Visual studio contains a bunch of different things:
The visual studio code editor
c# compiler and other build-tools
Microsoft C and C++ (MSVC) runtime libraries, aka vcredist
There is no need at all to use the visual studio editor, feel free to code in notepad if you want to. But you cannot really write c# programs without at least the c# compiler and the .net runtime, and you probably want to use at least some of the associated build tools. The potential MSVC runtime dependency is due to the native library, and does not really have anything to do with C#.
I want to wrap a library for python. Python is compiled with VS2010 and I have VS2013. Is it possible to force VS2013 to compile like VS2010?
PS. I have tried, unless the version of compiler that compiled python and the compiler that compiles the wrapper are the same it does not work.
PS. My python app has dependency to many other libraries and I can not recompile it with VS 2013
Many thanks,
Yes, you can change the Platform Toolset option on the project's General property page. Note: you must have both VS2013 and VS2010 installed, along with the proper Windows SDKs.
https://msdn.microsoft.com/en-us/library/vstudio/ff770576(v=vs.110).aspx
I'm aware that Python extensions on Windows typically have to be built with the same version of Visual Studio used to compile Python itself, and I'm further aware that Python 2.7 through 3.1 are built using Visual Studio 2008. But the machine I'm on already has VS 2013 installed, and, as I've discovered countless times, one way to rapidly mess up your Windows development environments is to install Visual Studio in any order than from oldest to newest. Besides which, install VS2008 on a brand-new Windows 8.1 box seems silly. Python extensions are the only thing I have that needs 2008; if I can avoid installing it, I'd really prefer not to.
Can I avoid installing VS 2008 and still build against the official Python distributions, perhaps by installing a specific Platform SDK? If not, is there an alternative build of Python that might go with e.g. MinGW, or something that does not require I install VS 2008?
I can suggest a few possible solutions to your problem. From potentially the easiest, to probably the hardest:
Just use Visual Studio 2013 to compile your extension modules. For this to work your extension module mustn't access any C runtime objects created by the Python interpreter, nor may it pass any C runtime objects it creates to the interpreter. In particular you can't use any FILE * or file descriptor objects provided by Python. You can still read and write to files in your module, just not files that Python has opened.
Uninstall Visual Studio 2013, install Visual Studio 2008, reinstall Visual Studio 2013. As silly as this sounds it's probably going to be a quicker and lot less frustrating than either of the following solutions. This will let you build extension modules pretty much normally and you won't have to worry about what C runtime objects you use.
Use mingw32 and employ various hacks to get it to work. This page explains how one person got it to work: https://lists.launchpad.net/kicad-developers/msg09473.html
Copy the appropriate msvcrt*.lib file from VS 2008 installed on another machine. Manually edit your linker options to use this library instead of VS 2013's msvcrt*.lib of the same name. If that doesn't work, copy the include files and other libraries as well, and modify your compiler and linker options to use them instead. If that still doesn't work, copy the VS 2008 command line compiler and all of its dependent DLLs, set the PATH correctly, and then modify your build process to use that compiler instead.
Firstly, I should state that my current development environment is MSYS + mingw-w64 + ActivePython under Windows 7 and that on a normal day I am primarily a Linux developer. I am having no joy obtaining, or compiling, a version of the Python library with debug symbols.
I need both 32bit and 64bit debug versions of the Python27.dll file, ideally. I want to be able to embed Python and implement Python extensions in C++, and be able to call upon a seamless debugging facility using the gdb-7.4 I have built for mingw-w64, and WingIDE for the pure Python side of things.
Building Python 2.7.3 from source with my mingw-w64 toolchain is proving too problematic -- and before anyone flames me for trying: I acknowledge that this environment is unsupported, but I thought I might be able to get this working with a few judicious patches (hacks) and:
make OPT='-g -DMS_WIN32 -DWIN32 -DNDEBUG -D_WINDOWS -DUSE_DL_EXPORT'
I was wrong... I gave up at posixmodule.c since the impact of my changes became uncertain; ymmv.
I have tried building with Visual C++ 2010 Express but being primarily a Linux developer the culture-shock is too much for me to bear today; the Python project does not even import successfully. Apparently, I need Visual C++ 2008, yet I am already convinced I don't want to go down this road if at all possible...
It's really surprising to me that there is not a zip-file providing the requisite .dlls somewhere on the Internet. ActiveState should really provide these as an optional download with each release of ActivePython that they make -- perhaps that's where the paid support comes in ;-).
What is the best way to obtain the Python debug library files given my environment?
I've just built CPython 2.7.5 in debug mode with Visual Studio 2012 Express (free).
I documented the process via wiki page: https://wiki.python.org/moin/VS2012
The best way to create a debug version of Python under Windows is to use the Debug build in the Visual Studio projects that come with the Python source, using the compiler version needed for the specific Python release, i.e. VS 2008.
There may be other ways, but this is certainly the best way.
If you really need a 64-bit debug build also, the best way is to buy a copy of VS 2008 (i.e. not use the Express version). It may be possible to create an AMD64 debug build using the SDK 64-bit compiler, but again, using the officially-supported procedures is the best way.
The libs can be aquired from the official Python site https://www.python.org/ftp/python/. Just navigate to the specific version you like and then download the respective installer.
For installation you can call the installers like this :
your_installer.msi targetdir="the_path_to_your_directory_of_choice"
or simply Run them as Administrator.
You may also use the Python installer to download the debug symbols as well(use the webinstall version).
RDFLib needs C extensions to be compiled to install on ActiveState Python 2.5; as far as I can tell, there's no binary installer anywhere obvious on the web. On attempting to install with python setup.py install, it produces the following message:
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
There are various resources on the web about configuring a compiler for distutils that discuss using MinGW, although I haven't got this to work yet. As an alternative I have VS2005.
Can anyone categorically tell me whether you can use the C compiler in VS2005 to build Python extension modules for a VS2003 compiled Python (in this case ActiveState Python 2.5). If this is possible, what configuration is needed?
The main problem is C run-time library. Python 2.4/2.5 linked against msvcr71.dll and therefore all C-extensions should be linked against this dll.
Another option is to use gcc (mingw) instead of VS2005, you can use it to compile python extensions only. There is decent installer that allows you to configure gcc as default compiler for your Python version:
http://www.develer.com/oss/GccWinBinaries
I can't tell you categorically, but I don't believe you can. I've only run into this problem in the inverse situation (Python built with VS2005, trying to build with VS2003). Searching the web did not turn up any way to hack around it. My eventual solution was to get VC Express, since VC2005 is when Microsoft started releasing the free editions. But that's obviously not an option for you.
I don't use ActiveState Python, but is there a newer version you could use? The source ships with project files for VS2008, and I'm pretty sure the python.org binary builds stopped using VS2003 a while ago.
As of today Mar 2012, I can categorically say it is possible with Python2.4.4 (only one I've tested) and Visual Studio 2005 and 2008. Just installing VS10 to check that. I don't know why it works and I have problems using distutils so I have to compile manually.