Wrong python interpreter being used when debugging embedded target - c++

I'm running CLion (2017.3 RC) with MinGW-w64 (5.0.3) and using gcc/g++ (7.2.0) + CMake (3.9.3) on Windows 10 x64 to compile a target that embeds python (3.6.3 64 bit). Everything works fine when run, however when I try to debug it and step through with CLion, I get
File "C:\Python36\Lib/site.py", line 178
file=sys.stderr)
^
SyntaxError: invalid syntax
I have my PYTHONPATH pointing towards a Python 3 installation. I do not have Python 2 installed on my system yet it seems like a Python 2 interpreter is trying to use the Python 3 Lib. After some digging I noticed that MinGW-w64 has Python 2 bundled with it but even if I delete the libs, include, and exe, I get the same error.

After some more digging I learned that python2 has been embedded in gdb from version 7.0+. Because of this, if you try to run MinGW64's gdb (like trying to debug from CLion) and you have PYTHONPATH pointing towards a python3 installation, you'll run into a syntax error. This happens because the embedded python2 is trying to use the python3 libs.
I am still unable to debug my C++ target that embeds python but that's a different issue...

Related

How to make gdb command source use python 2 instead of python 3?

I am trying to debug c++ program. I source a script from gdb which is written in python 2.7 and it supposed to recursively print object values. Python 3 was already installed in my linux machine. So I installed python2.7 and now my machine has both python 2 and python 3. Now when I run the source command in gdb environment, it still uses python 3 and the script does not run. How do I set it to run on python 2.
I have tried setting alias python=/usr/bin/python2.7 in .bashrc.
I do not want to uninstall python 3 as other services depends on it.
Expect gdb to use python 2 while doing source python script.
Python 3 was already installed in my linux machine. So I installed python2.7
Installing Python 2.7 will have to effect on GDB: what matters is which version of Python was your copy of GDB compiled and linked against.
To get a GDB built against Python 2.7, you will most likely have to build GDB yourself (use --with-python=... when configuring your GDB).

f90wrap on Windows (Python wrapper for Fortran 90)

I've got a Python program that calls Fortran routines. These Fortran routines are wrapped with f90wrap (https://github.com/jameskermode/f90wrap), and I've verified that the setup works correctly on Linux and Mac OSX. I'm now trying to get the setup to work equally well on Windows (because I collaborate with people who cannot sometimes switch to Linux).
I've got gfortran working through a MinGW installation and verified that Fortran programs compile and run without errors. I've also verified that a Python 2.7 installation works without issues, and was able to use pip to add numpy, matplotlib and scipy modules without issues. Both MinGW and Python are 64-bit, running on Windows 10. I've also got CMake to create Makefiles that compile standalone fortran programs using mingw-make, so the only part left (to get things working on Windows) is to make sure the Python wrapper for Fortran-90 works. That's where I ran into some issues.
I'm running mingw-make in Powershell (which executes in cmd.exe, I believe).
Q1: The pip installation for f90wrap failed with an absolute path/relative path error (https://github.com/jameskermode/f90wrap/issues/73)
A1: I downloaded the source and ran "python setup.py install", and that got stuck as well. I ran into a "multiple_definition" error with Windows 10, Python 2.7 and mingw-w64.
F:/Programs/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-atonexit.o):atonexit.c:(.text+0xc0): multiple definition of atexit' F:\Programs\Python\libs/libmsvcr90.a(deoks01081.o):(.text+0x0): first defined here F:/Programs/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-mingw_helpers.o):mingw_helpers.c:(.text+0x0): multiple definition of_decode_pointer'
F:\Programs\Python\libs/libmsvcr90.a(deoks00231.o):(.text+0x0): first defined here
F:/Programs/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-mingw_helpers.o):mingw_helpers.c:(.text+0x10): multiple definition of `_encode_pointer'
F:\Programs\Python\libs/libmsvcr90.a(deoks00241.o):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
error: Command "gcc -g -shared build\temp.win-amd64-2.7\Release\f90wrap\arraydatamodule.o build\temp.win-amd64-2.7\Release\programs\python\lib\site-packages\numpy\f2py\src\fortranobject.o -LF:\Programs\Python\libs -LF:\Programs\Python\PCbuild\amd64 -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\f90wrap\arraydata.pyd" failed with exit status 1

Not being able to run Theano on windows XP 32 with Anaconda

I’m trying to run Theano on windows XP 32 with Anaconda (Python 2.7). I installed Theano following the steps provided in the Anaconda section here: http://deeplearning.net/software/theano/install_windows.html. Everything went fine but when I try to run the script import theano I get this error message:
ImportError: DLL load failed: The specified procedure could not be found. Struggling quite a bit, could anyone please help?
I had the same issue. Now I can use Theano on Windows XP 32bits with Anaconda.
With dependency walker, we found when 'import theano', the error 'ImportError' caused by LIBSTDC++6.DLL(a g++ DLL) cannot import the non-exists symbol 'vsnprintf' in 'MSVCRT.DLL'.
The key to fix this issue is, replace the mingw installed by 'conda install mingw' (rev 4.7.0). Install mingw g++ (rev 4.9.3) with 'mingw-get-setup.exe' from sourceforge instead.
Make user you PATH environment has 'C:\MinGW\bin;C:\MinGW\lib;' (default install location) to use the correct g++.
Good luck!

Installing anaconda to use with windows

I am lost in the installation process of installing anaconda on windows.
I've installed the windows 32bit package (I'm running windows 7 x64)
I have anaconda in the start menu and I can open the python console and use scipy.stats.t.interval(), the function I am interested in.
However, how do I go about including this in another python program? I think it's something like adding it to the path. For instance, I have the scipy.stats.t.interval() function call in my other python file which I run through cygwin via python myscript.py. However it returns the error:
from scipy.stats import t
ImportError: No module named scipy.stats
I think it might be a change of path / add to path issue, but I'm not sure how to fix it :/. While I try to fix it, I figure I will post for help here.
well you might have two installations of python, one inside the anaconda package, and other which you might have installed earlier. try doing :
which python
from CygWin console.
If it returns:
/usr/bin
then it is definitely a add-to-path problem.
to fix it for CygWin,
you have to add the python installation from anaconda to the path.
try this fromn CygWin:
PATH=path-where-anaconda-is-installed/anaconda/bin:$PATH
and then doing:
which python
should give you:
/path-to-anaconda/anaconda/bin
and then it will work.
Cheers

Install Numpy compiled for VS2010 for an embedded interpreter

Another of my queries about an embedded Python 2.7.3 interpreter on Windows. I need to install numpy and matplotlib as support packages for an embedded interpreter in a C++ program compiled in Visual Studio 2010.
Some background:
I've been trying to make this work for a few months. The main issue is that numpy for Python 2.7 is compiled against an earlier version of the MS C library (VS2008) whereas my application is compiled against the 2010 version (a fact beyond my control - that is the office compiler).
I worked around this by fiddling with the manifest for my application to let it load the correct C library for numpy and this got it to import. As an end-user has tried out new features, bugs have started to appear, including untraceable crashes.
My current state:
I pinned some of these down to a poor compilation on my part of the Python 2.7.3 source, in particular the dependencies (lots of the crashes seemed associated with Tkinter from matplotlib). So I started afresh on the Python compilation and now have a clean compiled version of all the core and dependencies of Python 2.7.3. Now I'm looking at numpy/matplotlib.
My questions
Is it worth attempting to compile numpy against VS2010 or is my earlier manifest mangling solution the only way?
If the former, what problems might I encounter in doing so (i.e. what should I watch ou for)?
In the latter, how do I get numpy to install in the lib/site-packages folder of my embedded intepreter?
use cygwin to build numpy on windows.
I am on windows-xp
Its working fine for me.. .!
In cygwin python2.6 comes as a default python. I have installed python2.7 but not installed numpy in python2.7.
To use it on python2.7 i have run python2.7 setup.py build
You can see that in screen-shot of my terminal. and in folder 'namit' i have placed 'numpy' dir that i have compiled on cygwin.
when i have imported numpy when i am in that dir.. it worked...you can see that in globals() from where it has imported.