Debug Cython with python-dbg fails with undefined symbol: Py_InitModule4_64 - debugging

I am trying to debug a small cython project following the instructions from the official Cython page. but the command:
python-dbg setup.py build_ext --inplace
fails with the error below. I have seen responses to a similar issue here but I don't think it applies for me as I am running Cython installed via apt-get. Any help would be much appreciated.
Traceback (most recent call last):
File "build.py", line 4, in
from Cython.Build import cythonize
File "/usr/lib/python2.7/dist-packages/Cython/Build/init.py", line 1, in from Dependencies import cythonize
File "/usr/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 51, in from Cython.Compiler.Main import Context, CompilationOptions, default_options
File "/usr/lib/python2.7/dist-packages/Cython/Compiler/Main.py", line 17, in from Scanning import PyrexScanner, FileSourceDescriptor
ImportError: /usr/lib/python2.7/dist-packages/Cython/Compiler/Scanning.so: undefined symbol: Py_InitModule4_64
[35101 refs]

I had the same problem.
In this article the cause of it is explained:
The problem [..] is the python-dbg binary however is incompatible with
modules not compiled with them
http://hustoknow.blogspot.de/2013/06/why-your-python-program-cant-start-when.html
My solution was to uninstall cython (which was installed via pip), clone the cython github repo and manually install it with python-dbg:
git clone git#github.com:cython/cython.git
cd cython
sudo python-dbg setup.py install
Afterwards I was able to python-dbg setup.py build_ext --inplace in my own code.

Related

How to debug pip install <package name>

If I want to debug the setup.py file of my package packagename getting installed via "pip install packagename" , is there a way to do so? I have tried downloading the source, adding set_trace() in setup.py and run:
pip install .
However, as soon I get pdb() prompt, the install fails with error:
processing /Users/skauser/python-ibmdb/IBM_DB/ibm_db
Complete output from command python setup.py egg_info:
> /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py(31)<module>()
-> machine_bits = 8 * struct.calcsize("P")
(Pdb)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/setup.py", line 31, in <module>
machine_bits = 8 * struct.calcsize("P")
File "/Library/anaconda3/lib/python3.7/bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "/Library/anaconda3/lib/python3.7/bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/b6/pmddncpn77550p8_g9kkx9f40000gp/T/pip-req-build-_fg8s5a2/
Although I can debug the source via: python setup.py build, the behavior that I want to debug is applicable when installed through pip.
Pip is a python program. You can see it's content with cat $(which pip). Then you can copy it to a new file in your project's directory. For example, here is how it looks like for me:
File mypip.py:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Then you can add a breakpoint with pdb or use PyCharm as mentioned in the answer from Igor Yudnikov.
For reference, this is how it to looks like in my Pycharm
Oh! Just found a solution, its pretty easy. What is pip? It's a plain python file, which is I think somehow bound to run via python, and under the hood system makes something like
python pip install ...
so, at first we need to know where is pip
which pip
says
/Users/me/PycharmProjects/etlscripts/venv/bin/pip
So, we may go to Pycharm, create config like
then you'll be able to catch your exception. Cheers.

Cannot import open cv2 in python. Error: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel [[Cannot upgrade numpy ]]

I and trying to build something on python package cv2. My os is Mac OS X El Capitan and python version is python 2.7.10.
But when I import cv2 as
>>> import cv2
I get following error.
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
I figured out that it is a problem of numpy version and I need to upgrade it. So I tried
sudo pip install numpy --upgrade
But system threw following error:
OSError: [Errno 1] Operation not permitted: '/tmp/pip-JSOF8d-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'
Then I tried to install a particular version of numpy (required version) using following command.
pip install numpy==1.8
Even this didn't work and I got following traceback error:
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
Now I am clueless, how to proceed. Please help me to figure this out.
Thanks in advance.
I was also facing the same issue, 2 things which solved my problem are
Run
pip install --ignore-installed numpy
run the above command in terminal, that is don't use setuptools.
But, it will upgrade to latest version of numpy, hope this resolves your problem. Its been quite tough for me to fix couple of el-capitan issues

Why does IronPython tell me that pip is a package and not an executable?

I am a complete newbie at Python. I wanted to try to see if Pyomo (a Python package for mathematical modeling) could work under IronPython because all my code for generating the data needed for Pyomo is in C#.
I installed IronPython 2.7.5, then tried as an administrator the advice found in http://blog.ironpython.net/2014/12/pip-in-ironpython-275.html#disqus_thread on how to run "pip" for IronPython. I used the exact example they gave (installing html5lib):
ipy -X:Frames -m ensure pip
ipy -X:Frames -m pip install html5lib
The first line worked, and I see in the Lib/site-packages directory a folder called pip-6.1.1-py2.7.egg with lots of python code in it.
For the second line, I received the error:
Unhandled exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 170, in run_module
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 111, in _get_module_details
ImportError: No module named urllib; 'pip' is a package and cannot be directly executed
At this point, I'm stuck. Any help would be appreciated.
Just in case this helps, printing out the sys.version gives:
2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.34209 (32-bit))
I encountered the same problem. It seems that IronPython can't deal with more recent versions of pip. What I did was:
remove all traces from pip and setuptools from IronPython's Lib\site-packages folder
run from a commandline: ipy.exe -X:Frames -m ensurepip
this installed an old version of pip, one that IronPython understands. Verify this by checking that a folder pip-1.5.6.dist-info appears in IronPython's Lib/site-packages
Moral of the story; don't upgrade to a newer pip version when using IronPython

Python3.4.1 LINUX - from pip import main raises ImportError: Cannot import name 'main'

I'm using a server for which I am not root, and I have several scripts requiring Python 3.4.1. I built the software from the source tarball using the following syntax
$ ./configure --prefix=$HOME
$ make
$ make install
The software installed successfully, as I was able to launch python3 after modifying my .bash_profile to look in $HOME/bin. However, Pip was not so lucky.
$ pip3.4
Traceback (most recent call last):
File "/home/scnorton/bin/pip3.4", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
When I tried to run python3 get-pip.py, I get the following error:
Traceback (most recent call last):
File "get-pip.py", line 17474, in <module>
main()
File "get-pip.py", line 17466, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 17406, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
I have checked the /usr/lib64 directory and concluded that zlib is installed on the server. I even executed the command module load zlib-1.2.8-1 and tried reinstalling pip again, with no luck. Could the problem be that Python3.4.1 is installed as a 32-bit application? If so, where can I go to get 64-bit Python3.4.1 for Linux?

HTTPLIB2 Error installing python-twitter on mac osx

Hello I am trying to install python-twitter and one of the dependencies HTTPLIB2 is giving me a lot of problems. I have searched the internet up and down but maybe I do not know what the right key words are. Here is the problem.
I am installing python-twitter. I install the requirements either by "pip install -r requirements.txt" or doing them one by one through for example "pip install httplib2". Then I run "python setup.py install". It's happy but then "python setup.py test" fails as followed with an error on import HTTPLIB2.
python setup.py test
running test
running egg_info
writing requirements to python_twitter.egg-info/requires.txt
writing python_twitter.egg-info/PKG-INFO
writing top-level names to python_twitter.egg-info/top_level.txt
writing dependency_links to python_twitter.egg-info/dependency_links.txt
reading manifest file 'python_twitter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '.DS_Store'
writing manifest file 'python_twitter.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 73, in <module>
Main()
File "setup.py", line 66, in Main
setuptools.setup(**METADATA)
File
....
<deleted these parts to save space>
module = __import__('.'.join(parts_copy))
File "/Users/ME/Downloads/python-twitter-1.0/twitter_test.py", line 30, in <module>
import twitter
File "/Users/ME/Downloads/python-twitter-1.0/twitter.py", line 65, in <module>
import oauth2 as oauth
File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 32, in <module>
import httplib2
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 347
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
But I thought the print error was an incompatibility between python 2 and 3. Why am I getting this while I clearly have python 2.7 (I checked and uninstalled and reinstalled HTTPLIB2).
Thanks much for your help
i had a same issue. It seems to be python2.7 and 3.x version conflict issue and resolved by
python2.7 -m pip install -t lib/ -r requirements.txt
Just in case, this happens when you install httplib2 with a python3 version of pip and then execute it with python2.
This happens for example when creating manually an environment with:
pip install -t lib/ -r requirements
As it happens when creating an AppEngine standard environment vendor folder.
This happens because contrary to most of the libraries, httplib2 has completely different versions for python2 and python3.

Resources