I am using Ubuntu 12.04, Python 2.7.3.
I am having a segmentation fault in a C extension I have co-written. It seems to come from a pointer that was not free'd properly.
I then use valgrind to find memory leaks. According to that answer, I have to compile Python in debug mode to get a valgrind friendly version of Python and get rid of its irrelevant reports.
How to compile Python in debug mode?
Even though the answer I linked answers part of that question, it does not provide me enough details.
Indeed, I want to understand what is happening, not just type things at some places because "who knows? It could work".
Hence, I would like to know:
What to download to compile Python?
Where to type that ./configure?
What is going to happen to my current installation? Is it going to affect my system?
I have read at many places that many processes on Ubuntu 12.04 are
managed by Python and I do not want to mess up anything.
I am also trying to find answers to the questions mentioned by Yair Daon's comment:
Do you have to recompile Python once you are done using its debug
compilation?
If yes, how to compile Python back to its standard mode?
Here are some inputs for anyone trying to compile Python in debug mode on Ubuntu:
Download the version you need from the python website.
Untar it using tar -xf and go to the new directory.
Example:
tar -xf Python2.7.3.tgz
cd Python-2.7.3
Configure your python installer for debug mode, using ./configure --with-pydebug. It will create a Makefile that you will just have to run.
Compile the sources to create your new python interpreter by running the Makefile, using: make install.
As you create a new interpreter, your system's Python will stay clean.
If you compiled it using --prefix=/home/username/workspace/project/python/, you can now run your script with your new Python interpreter using:
/home/username/workspace/project/python/bin/python script.py
Or, you can also add the shebang line #!/home/username/workspace/project/python/bin/python at the beginning of your script, give it the execute privilege (sudo chmod 764 script.py) and run it more easily using your new Python interpreter by typing ./script.py.
Note: you may want to check Python's documentation for more configuring / compiling flags
(such as --prefix / -j, thanks Chris for the link).
Related
So this is probably a very newbie question (which I am) but looking for tools for C++ code I found cppclean, so I follow the instructions on the repository cppclean but when running cppclean from a cmd terminal I get cppclean is not recognized as an internal or external command I guess I am missing some steps apart from doing pip install cppclean do I need to compile it or anything like it? I have tried to run it from the cmd and the python terminal. Is it even possible to run cppclean in windows or is it just for unix systems? Sorry if the question is too obvious but I have very little python knowledge.
You have to add the Python scripts path, e.g. C:\Users\USER\AppData\Local\Programs\Python\Python37-32\Scripts, to your system environment Path variable. (Replace USER with your actual user name and Python37-32 with your actual Python version). It's described here
During the past weeks I was wandering around for a problem with QtCreator and LLDB v9, when I started the debug process, an exception of the ubuntu system exception arose, the exception dialog informed that No module named _lldb, and the debugging process within QtCreator hungs up.
The configuration of my system is:
Ubuntu 19.10 x64
Qt 5.14.1
Qt Creator 4.11
lldb-9
python-lldb-9
At the beginning, I thought that there was a problem with lldb-9, because when I used lldb-7 there was not problem, and for that reason I decided to debug manually my program, and guess what, lldb-9 worked swiftly debugging my program under console.
Then, I thought that the problem has to be python, then I installed python3-lldb-9, but nothing changed.
Doing an internet research, I found this post: How to import lldb in a python script. That post showed me that the very python does not load the lldb module due that module was designed to run within lldb command line. But for sure, QtCreator needs it in order to run lldb properly.
Finally, running lldb -P command, I found the solution. You need to make two missing symlinks, this way:
Go to your python-lldb version, in my case is:
cd /usr/lib/llvm-9/lib/python3.7/site-packages/lldb
Then, create the symbolic link to liblldb.so.1 with python-like module name:
sudo ln -sf ../../../liblldb.so.1 _lldb.so
In my experience, there is no need to link more libraries within that directory.
Finally, command lldb -P shows the alias for --python-path del LLDB, that in my case is:
/usr/lib/x86_64-linux-gnu/python3.7/site-packages
But, that directory does not exist. So, you need to create a new symlink:
cd /usr/lib/x86_64-linux-gnu/
mkdir python3.7
ln -sf /usr/lib/llvm-9/lib/python3.7/site-packages/ site-packages
Make sure that you have the python version properly selected in QtCreator options, and try to debug within QtCreator.
Note: if you want to import lldb module within the python3 shell, you have to export the python path like this:
export PYTHONPATH='/usr/lib/llvm-9/lib/python3.7/site-packages'
Maybe this approach works for python2.7, I find this solution easy, and maybe this is an Ubuntu 19.10 bug related with lldb-9 and python-lldb packages, don't know, but if any of you have a clue about this, I appreciate additional info.
I have been trying for hours to install SCons on my Windows 8.1 machine and simply cannot. I honestly have no idea whatsoever what I'm doing wrong, or really what I'm doing in general. Here is the step by step process of what I have done
1: installed Python 3.7 from www.python.org I used the python-3.7.3-amd64.exe to install it, it seems to have worked (I have never used python before so if anything is off I wouldn't realize it). When I use the command console and input 'python --version' it outputs 'Python 3.7.3'
2: I downloaded scons-3.0.5.zip from www.scons.org I followed the website's instructions as best I could. I used 7zip to extract it's contents into a new file called 'scons-3.0.5' located at C:\ It's complete path, therefore, is C:\scons-3.0.5
3: I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5' just as the scons website says to do. It outputted nothing, and I noticed that the new line started with '...' instead of '>>>', I have no previous experience with Python so I don't know if that's good or bad. I then continued to follow the instructions by inputting '# python setup.py install', it outputted nothing, and once more the new line started with '...'. I hoped that was all I needed to do but in the command console I inputted 'scons --version' (I read somewhere this can be done to check if it is installed), it outputs "'scons' is not recognized as an internal or external command, operable program, or batch file.". This, combined with the fact that seemingly nothing is different, leads me to believe it has not been installed.
4: I tried to do something a bit different. I noticed that the zipped file I downloaded from the scons website contained 2 files in it, 1 being scons-3.0.5, the other being pywin32-master.zip, I had both of these in the file C:\scons-3.0.5 I decided to delete that file, and in its same location place the scons-3.0.5 file. Now instead of C:\scons-3.0.5 including scons-3.0.5 and pywin32-master.zip it contained just the contents of the scons-3.0.5 file that was in it before (if that makes sense, I might clean it up in the morning and make it easier to read). I once more did step 3, and the results were no different.
I have no idea what I'm doing, I have no prior experience with Python or the command console, I just want to set up scons and never use Python again. Does anyone know how I can fix this? I have googled for hours but it seems as if I'm the only one who's having this issue.
The contents of the zipped file from scons website:
contents of the scons-3.0.5 file in the zipped file
I doubt the images will help but I have included them just in case if they seem off
edit: I did know what installing via Pip was, but I googled it and it worked just fine! Thanks to Alexander Lopatin and bdbaddog for the help
So you're mistake is in step 3.
I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5'
The website says:
# cd scons-3.0.5
# python setup.py install
Notice this is
cd into the unzipped directory
THEN run python setup.py install
Instead you've run python, then typed a shell command into python. Which is why you had issues.
Note: On windows you shouldn't need to run as admin to install SCons.
Although as #dirkbaechle said. Pip is the preferred method to install python.
python -mpip install scons
But if you'd rather follow the instructions. Just bring up a windows command shell, or powershell if you like, cd into the unzipped directory, and run python setup.py install
BTW. There's an IRC channel and a users mailing list for SCons support.
https://scons.org/contact.html
Hello gyus i have started python and i want to know how can i excecute python file without using terminal.Just like the most games using (exe) file extension but for py files.I have tried py2exe but it doesn't show anything on the screen. I tried to make excecutable the py file with no luck. Please tell me how to excecute the and if there is an option whithout using a specific program for that.
My system is : Windows 7 / Ubuntu 12.04
Here, have a look in my blog, It explains how ca you do it in Ubuntu.
http://insidepython.wordpress.com/2012/08/04/hello-world-or-how-or-say-ni/
but basically:
Add this line to the beginning of your script
#!<location of your python interpreter>
To find out where your python interpreter is installed:
$ sudo find / -name "python"
After executing the previous, you should get the location of your python interpreter, then you need to set the environment variable, in my case python executable is located in /usr/bin/python
$ export PATH="$PATH:/usr/bin/python"
Then you need to set the file attributes to executable, you can look more into file attributes in Unix/Linux here http://en.wikipedia.org/wiki/Chmod
$ chmod +x shrubbery.py
And finally to execute your application
$ ./shrubbery.py
For Windows, there's also a python script called GUI2Exe that I have used in the past to create distributable versions of python scripts as apps. It's available at
http://code.google.com/p/gui2exe/ and is, in my opinion, very simple to use. Tutorials and whatnot are easy to find on Google.
It uses py2exe (or any other Python compiler library) to put together the script, but it doesn't require any syntactically annoying setup.py file.
gdb shows the following when I type "show version":
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.2)
I followed the instructions on this website for setting up pretty printing with Eclipse:
http://wiki.eclipse.org/CDT/User/FAQ#How_can_I_inspect_the_contents_of_STL_containers.3F
When I attempt to start gdb with my new .gdbinit file, I get the following error:
Error in sourced command file:
Python scripting is not supported in this copy of GDB
So then I researched around for a way to enable this. I have over version 7.0 so it should be able to support Python scripting. GDB's website mentions calling the GDB configure script with the --with-python option. However, I don't see a configure script anywhere in my system. There are multiple developers using this machine so I don't want to have to reinstall GDB or anything like that. Is there a way to configure the existing GDB installation to enable python scripting? Thanks!
To get you started, you can compile GDB in a separate directory, and run it from there.
Grab the sources for the version you want:
http://sources.redhat.com/gdb/
Run ./configure with the --with-python, and then make, but don't install it over your system copy.
At that point, you should be able to invoke gdb where it has been built with ./builddir/gdb, rather than the one in your path. (This is where you should point eclipse debugging to, if you want to invoke it from there)