Skip to content

Instantly share code, notes, and snippets.

@bombs-kim
Created December 27, 2018 14:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bombs-kim/c9848c2b09962f2fd753b48b6d2cd87f to your computer and use it in GitHub Desktop.
Save bombs-kim/c9848c2b09962f2fd753b48b6d2cd87f to your computer and use it in GitHub Desktop.
How to install a custom python binary(ex. python-dbg) in your conda environment.
# This instruction is for Unix-like OS users.
# I refered to the following guide when I wrote it.
# https://conda.io/docs/user-guide/tasks/build-packages/recipe.html
# Activate an environment if needed
conda activate myenv
# Install conda-build if you haven't. Ironically, installing conda-build
# includes installing python. This python will be effectively replaced with
# your new python binary so don't worry.
conda install conda-build
# Make a directory. You can give it any name.
mkdir python-dbg
cd python-dbg
# Download example files(meta.yaml, build.sh) from
# https://github.com/conda/conda-recipes
wget https://raw.githubusercontent.com/conda/conda-recipes/master/python/python-3.5/meta.yaml
wget https://raw.githubusercontent.com/conda/conda-recipes/master/python/python-3.5/build.sh
# Modify the downloaded files. You change them to build a different version of
# Python or to add compile flags. Refer to Python developer's guide to learn
# more about build options. https://devguide.python.org/setup/
# For example, you can make following changes in build.sh
#
# ./configure --enable-shared --enable-ipv6 --prefix=$PREFIX --with-pydebug
# make -j16
cd ..
# Hope that the build will succeed or you have to figure out
# how to solve the build problem on your own.
conda-build python-dbg
# When conda build is finished, read the log message carefully and find
# the package filename and location. In my case, it looked as below
# ..../conda-bld/linux-64/python-3.5.0b4-0.tar.bz2
# This is what's called a package in conda
# Actually install the package
# This part is not documented well in the official conda tutorial so I
# figured it out by reading `conda install -h` message. I'm not sure if
# this is the official way to install, but it worked for me.
conda install --use-local ..../conda-bld/linux-64/python-3.5.0b4-0.tar.bz2
# Make sure if python has been installed
conda list | grep python
# Make sure a python-with-pydebug(ex. python3.5dm) was installed along with
# a normal python(ex. python3.5m)
which python3.5
which python3.5dm
@petioptrv
Copy link

Hey Beomsoo, I'm trying to get this configuration working and I think I'm close, but having some issues that I wanted try to get your input on. I think I manage to compile Python with debug on Conda's end, but when I run cygdb in the directory of a properly compiled library, I get

Python Exception <type 'exceptions.ImportError'> No module named gdb: 
gdb: warning: 
Could not load the Python gdb module from `/usr/local/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
GNU gdb (GDB) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin19.4.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython/Debugger/libcython.py", line 19, in <module>
    import gdb
ImportError: No module named gdb
/var/folders/jb/dbcl7ts10z7bqhzmxb23g_lc0000gn/T/tmp9EJDYW:19: Error in sourced command file:
Error while executing Python code.

Any pointers on how to solve this? Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment