Menu

Could re-compiling Python using Visual Studio 2010 be avoid?

Help
Neosettler
2013-05-28
2013-05-30
  • Neosettler

    Neosettler - 2013-05-28

    Greetings,

    Is there a way to use PythonQt with VS 2010 that would not require to distribute a re-compiled version of Python?

    As I understand, Python 2.7.x on Windows uses VS 2008 compiled libraries and using those libraries with VS 2010 is probably not recommended but I got around this quite nicely by not using FILE::open and use python file system instead:

    PyObject *l_pyFile = PyFile_FromString((Char*) in_path, "r");
    Int l_status = PyRun_SimpleFile(PyFile_AsFile(l_pyFile), in_path);
    

    I tried to modify PythonQt accordingly but without success. I'm getting a crash with PythonQtObjectPtr::evalFile (while generating the pyc files I believe) that I do not know how to solve.

    Any hint on the subject would be very appreciated.

     

    Last edit: Neosettler 2013-05-28
  • Florian Link

    Florian Link - 2013-05-28

    Mixing DLLs from different VC compiler versions is not recommended and can have bad side effects because the CRT runtimes do not mix well, especially if the code uses cross DLL allocations. Mixing debug and release is also troublesome.
    So if it crashes on you now and you find the reason, it will crash somewhere else later on.

    Embedding Python in a C++ application is somewhat different to just extending an installed Python with some extensions. We built Python ourself for all compilers that we support and I think it is a requirement for a clean deployment

     
  • Neosettler

    Neosettler - 2013-05-28

    I definitely agree, somehow replacing Python with a compiled one is mind boggling. I'm looking forward to get my hands on JC's blog on this topic.

     
  • Neosettler

    Neosettler - 2013-05-28

    Meanwhile, if it is not too much to ask, lets say we have not installed Python on a client PC and we'd like to rely on our own version of Python that would reside in our API root folder. Any idea where I could get a "how to" I could chew on?

     
  • Neosettler

    Neosettler - 2013-05-29

    I'm sorry if I'm stretching it but I can almost see the light at the end of the tunnel after many days of darkness. I compiled Python2.7.5 successfully but I'm still not sure what to do with it. Is it possible to link my dev project to the compiled Pyhton27.lib and use the installed Python27 executable and modules to launch my python scripts or I can't rely on the default installation of python at all? In that case, I'll need to compile the executable as well and any other library that I'm using in conjuncture with PythonQt like ctypes for instance?

     

    Last edit: Neosettler 2013-05-29
  • Chris Bevan

    Chris Bevan - 2013-05-29

    Hi,

    You might want to have a look at some of the information out there about embedding Python, which might answer some of your questions - e.g.:
    http://docs.python.org/2/extending/embedding.html
    http://docs.python.org/2/extending/index.html

    In essence, though, you'll need to compile all of Python and the libraries that you need (including ctypes), though it's not really all that bad. Once that's done, you can link your application to python27.lib or such, drop python27.dll next to your application, put the libraries including os.py in a subdirectory of your application's folder called "lib\python27", put the "DLLs" folder (the one with the .pyd files) alongside your application, and hopefully that should do it. I might have some of the file names wrong, though, as I haven't built on Windows for a while. Anyway, you don't need any python.exe when you're embedding it in your own application.

    Cheers,

    • Chris
     
  • Neosettler

    Neosettler - 2013-05-29

    Oh Genius!

    Here is my steps:

    • Compiled Python 2.7.5 from source: (BUILTIN_CTYPES_TEST and ENABLE_CTYPES_TEST checked)
    • Install Python 2.7.5 (needed for the .pyd).
    • Copied the Lib(from source) and DLLs(from installed .pyd) folders to my API's root/Python27 folder.
    • Remove Pyhton 2.7.5 default installation.
    • Add env PYTHONHOME=root\Python27
    • Add env PYTHONPATH=root\Python27\Lib

    When launching my app I evalFile a script that use ctypes and I'm getting :

    File "root\Python27\Lib\ctypes__init__.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
    ImportError: No module named _ctypes

    Any idea what am I missing?

     

    Last edit: Neosettler 2013-05-29
  • Chris Bevan

    Chris Bevan - 2013-05-30

    Sounds like you're missing _ctypes.pyd/.dll I think (but I can't remember which - not on Windows now). This should go in your "DLLs" folder. If it's in there already, have a look at your Python sys.path and check that it's looking where you expect. If it's not there, you'll probably find that it went to a different folder when you built Python - I remember it putting some things in different places; I'm not sure why - so have a look in your build directory tree, and it should be there somewhere.

    • Chris
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.