I've searched a lot on how to enable pretty printing in KDevelop with no hope.
I had found this link and implemented what was mentioned there. Then in "launcher configuration" I've added my gdbinit file as the "config gdb script". But it has no effect.
It was working well in older version of KDevelop without no manual configurations needed, but upgrading my Ubuntu to 14.04 and upgrading KDevelop to v4.6.0 seems like a miss.
Any ideas how to enable pretty printing in KDevelop?
Yes, I also had this same problem with Ubuntu 13.10 and KDevelop 4.5.1. Below, I've included both the problem and the solution.
Problem:
Ubuntu 13.10 uses GDB 7.61, which reads Python3 pretty-printer scripts, but Ubuntu 13.10 shipped with Python2 pretty-printer scripts. Oops!
Solution:
First, make sure that you have the needed “.gdbinit” file in your home folder – the one that your hyperlink references. This will inform GDB where to look for the
required Python3 pretty-printer scripts. It goes without saying, you might have to update the path in “.gdbinit”. Mine, looks like this:
python
import sys
sys.path.insert(0, '/usr/share/kde4/apps/kdevgdb/printers')
from qt4 import register_qt4_printers
register_qt4_printers (None)
from kde4 import register_kde4_printers
register_kde4_printers (None)
from libstdcxx import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
Now, you need to use the “2to3” shell command to convert the Python2 scripts to Python3 scripts. For example:
2to3 -w /usr/share/kde4/apps/kdevgdb/printers/qt4.py
2to3 -w /usr/share/kde4/apps/kdevgdb/printers/libstdcxx.py
I didn't need to convert the kde4.py script: it was already a Python3 script.
Note: Just to be on the safe side, backup the script files before you do the conversion – you never know.
That's all there is to it, fire-up KDevelop and away you go...
Actually, you can use the gdb shell command to fire-up GDB and make sure that all of your Python scripts are version 3: if you don't get any read errors, you know you're okay. If it generates read errors, simply convert those scripts.
FYI: To get out of GDB, just enter “quit” and press the “Enter” key: (gdb) quit
Addendum:
If your system doesn't contain the libstdcxx.py file, you'll need to do the following:
In the folder that contains your other pretty-printer scripts, create a file and name it libstdcxx.py
Go to the following web page:
http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python/libstdcxx/v6/printers.py
Now, copy the web page contents and paste it to your newly created libstdcxx.py file.
Since this file comes from gcc, it's more than likely a Python3 script - you'll have to see.
Related
Right now, I am tring to build Chromium on my own computer under instructions at https://chromium.googlesource.com/chromium/src/+/master/docs/linux/build_instructions.md#Build-Chromium
At first, it went smoothly. However when I run
$ autoninja -C out/Default chrome
when I run this to start build. It started. And then an error occured and the build process is terminated.
The error is
NameError: name 'unicode' is not defined" and I know it is a common error associated with the difference between python2 and python3.
However, I don't know how to let the ninja use only python2 and avoid this bug.
If you can help me, I will really appreciate it.
I recently ran into this issue when attempting to home build the Brave browser, which is chromium based. It appears that chromium build is based on python2, which is fine, but uses plain calls to "python" in the scripts. Obviously, essentially all modern distros put a symlink to python3 at python in the PATH (generally /usr/bin/python -> /usr/bin/python3). I still retain hope that there is a way to configure the "python path" in the build system, but have not found it and I am not too familiar with ninja.
The first way I "solved" this, and managed a successful build is one I consider a hack and do not recommend as a solution without the stipulation that it leaves your system broken so don't run too many other things. This is to manually temporarily update the symlink. Assuming you have both /usr/bin/python2 and /usr/bin/python3 on your system, remove the symlink at /usr/bin/python and replace it with one to python2:
sudo rm /usr/bin python
sudo ln -s /usr/bin/python2 /usr/bin/python
You can then run the chromium build, and reverse the above change when completed. Note that anything on your system that requires python3 to be at the symlink python cannot be run during this time. I have successfully used this technique to build Brave (and then reverse the change after the build completed).
I can offer you some other options too. One is to set up pyenv. If you search for that, you will find it is a suite that allows you to manage multiple python versions and have different directories use different ones. I researched this, and assume it can work, but have not done it myself.
The next option, which I am currently undertaking right now, is basically a manual watered down version of what pyenv does. I will let you know how it goes. The essence is to add a symlink in the path that will redirect python calls for that instance of the shell (and all subshells it creates). Assuming you are in the source directly at the obvious path:
mkdir .shims
ln -s /usr/bin/python2 .shims/python
export PATH=/home/yourname/src/Chromium/.shims:$PATH
python --version
This should print out whatever version of python2 you have rather than python. Anytime you come back to work here, you have to export the new PATH again. The rest of your system is unaffected, and still finds python3 at python. You can open up a new terminal and type python --version to verify that.
I have Chromium building on Fedora 33. Somewhere in the Chromium build, /usr/bin/python is getting run explicitly. On Fedora, that means Python 3.
If you change /usr/bin/python to point to python2.7, I bet your build will work.
Creating aliases for "python" won't work.
If this works, consider using the alternatives command to easily change /usr/bin/python:
alternatives command for /usr/bin/python
I just installed the new python3 module using terminal of Visual Studio Code on ubuntu.
When I import it, this error occurred.
[Python (analysis)] Unable to resolve 'new module'. IntelliSense may be missing for this module.
But the new module surely installed successfully. (I can import it in my ubuntu terminal)
How can I import that new python module in VS code?
You should look up the official docs on it. They have a neat tutorial to get you started.
Here are a few excerpts that should help you:
An "environment" in Python is the context in which a Python program runs. An environment consists of an interpreter and any number of installed packages. Because many programs are written specifically for a certain Python interpreter and makes use of a set of libraries, developers often create and manage an environment for individual programs.
When working with Python in VS Code, you select from available environments using the Python: Select Interpreter command. The Python extension then uses that selected environment for IntelliSense, auto-completions, linting, formatting, and any other language-related features. (The environment is not, however, used for debugging; see Choose a debugging environment.)
The selected environment is also automatically activated when using the Python: Run Python File in Terminal and Python: Create Terminal commands. Installing (or uninstalling) a package in the Terminal with a command like pip install matplotlib installs (or uninstalls) the package in whatever environment is active in that Terminal.
Note: By default, the Python extension looks for and uses on the first Python interpreter it finds in the system path. If it doesn't find an interpreter, it issues a warning. On macOS, the extension also issues a warning if you're using the OS-installed Python interpreter, because you typically want to use an interpreter you install directly. In either case, you can disable these warnings by setting python.disableInstallationCheck to true in your user settings.
I am trying to view the contents of C++ STL Containers. I read here that the recent versions of gcc and gdb support pretty printing by default but when I tried to display a map I got the following:
Then, I tried to set up pretty printing according to this answer but still it shows the same output. Can someone please help me out? Thanks.
I am using Ubuntu 16.04, g++ 5.4.1, GDB 7.11.1 and python 2.7.12 (installed from their official sources).
It was stated in the other thread you mentioned that some versions of GDB work with Python 3 only.
That can be ruled out as possible reasons since you don't receive any errors as far as your description says.
Over at sourceware.org it is suggested that
You can extend gdb using the Python programming language. This feature is available only if gdb was configured using --with-python.
Not sure if you did because the guides you used don't mention it directly.
Mark was correct. I built my own version of gdb 8.0 with --with-python option but still I was not able to see container contents. gdb was showing all complex structure. So I followed Mark's suggestion.
You need to create a soft link (auto-load) in your gdb install directory.
If your gdb install directory is $HOME/gdb_install then
cd $HOME/gdb_install/share/gdb
ln -s /usr/share/gdb/auto-load auto-load
/usr/share/gdb/auto-load already exists on my Ubuntu installation. It's the gdb version 7.11.1.
After that gdb is showing container contents. Thanks Mark.
The gdb native to Ubuntu 16.04 should be able to pretty print a std::map; the python code which handles that is class StdMapPrinter in the following file from the libstdc++6 package:
/usr/share/gcc-5/python/libstdcxx/v6/printers.py
If your goal is to accomplish this with binaries you build from source, it might still be useful to get this working with the native Ubuntu packages first, as a basis for comparison. The likely reason pretty printers are not working in a gdb you built yourself is that libstdcxx/v6/printers.py (libstdcxx.v6.printers in the python namespace) is not where gdb expects to find it.
Also, the gdb native to Ubuntu 16.04 is linked against python3, not python2; one way to see that is in the output of
ldd /usr/bin/gdb
It appears that the libstdcxx.v6.printers native to Ubuntu 16.04 is intended to work with either python2 or python3.
If your native gdb binary is not already installed, you can use this:
apt install gdb
I'm following CS231n and met a problem when doing assignment2: ConvolutionalNetworks: global name 'col2im_6d_cython' is not defined.
I think the problem was due to a failure in importing functions from im2col_cython.pyx, which used cython.
I've installed Xcode 7.3.1, as shown below, but the problem was still not solved.
I'm running the ipynb files in Jupyter from Anaconda. There is a related discussion on reddit, but unfortunately the solution here was for Windows, not Mac OS X.
Thank you for your time.
I wanted to add my input as a comment but didn't have enough reputation points to do so.
The issue was resolved for me when I closed the jupyter notebook and opened it again. I compiled the cython extension after I got the import error and probably have to relaunch it when the .so file is available.
I solved this with 2 easy steps:
In the terminal, run python setup.py build_ext --inplace in the cs231n directory.
Then reopen the notebook (if necessary, shutdown the notebook, the open it again);
Ps.: I tried this through the notebook using !python ./cs231n/setup.py build_ext --inplace as well. It does not work! You have to that outside the notebook, using the terminal.
I had this problem recently. I googled it a lot and also tried un-/-reinstall Anaconda. However it does work further. So I used "which python" to figure out which python's been using. And it turns out that the python included in Anakonda directory is used as default. I then tried the python2.7 in my macOS, which is located in /usr/bin/python2.7. Although I got a couple of warnings, but now it works likes charm. Perhaps it's kind of version problem. Solved in macOS Sierra 10.12.4.
I compared the two compiling results, as it shows that the include files are totally different. The one in Anaconda includes all header files in python3.6. Instead we need here corresponding header files in python2.7(I suppose). As the red circles point out.
enter image description here
Supported by python 3 onwards. Go to setup_googlecloud.sh and change the line
virtualenv .env
to
virtualenv -p python3 .env and run the setup again as explained in assignment1 setup..
Works well after that..
It occurred to me as well.
My problem:
I saw that the extention file that is created is named "im2col_cython.cp37-win_amd64.pyd" and the import is looking for im2col_cython alone, so I changed the file name to "im2col_cython.pyd" and ran the setup script again.
Now when I ran the code in the notebook it found the module but it said that the dll was compiled with a different python version. I use Anaconda envs and it turns out that since I ran the setup script from the cmd, it used a different python version than the one of the environment. I deleted the created files from the cs231n directory (im2col_cython.cp37-win_amd64.pyd and im2col_cython.c) and ran the setup script again, this time from the env Anaconda Prompt and it worked.
Solution:
remove already created files (the .c and .pyd files)
run the setup
script from the environment prompt (not plain cmd)
change the .pyd
file name into im2col_cython.pyd
Enjoy!
I have intalled SublimeLinter and sublimelinter-cppcheck packages to my Sublime Text 3.
The problem is that sublime text is saying SublimeLinter: WARNING: cppcheck deactivated, cannot locate 'cppcheck'. I figured out that cppcheck cannot find linter executable, so I decided that I will add path to linter to my system $PATH property. But the thing is that I cannot find linter executable on my system.
At first I thought that it's not installed but that I realised that it has to install with SublimeLinter package. But it did not. I tried to find it using Unix find command the only result is :
/Users/syky/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/cocoapods-core-0.34.2/lib/cocoapods-core/specification/linter
That is not what I am looking for.
I am using Sublime Text 3, Mac OS X Yosemite and ZSH as my shell.
SublimeLinter is looking for the cppcheck executable, which you apparently haven't installed. It is not looking for a file named linter. Please ensure that you have completely read and understood the SublimeLinter-cppcheck documentation before proceeding. The easiest way to install cppcheck is either via Homebrew or MacPorts (my personal favorite). Otherwise, you'll have to download and compile the source, which, if you're programming in C++, I assume you know how to do.
Once you have cppcheck installed, create a symlink to it in /usr/bin so Sublime can find it. Modifying your ZSH PATH won't do anything, unless you always launch Sublime from Terminal, because the PATH for programs launched from the Dock is different.