How do I debug python module loading? - python

I'm trying to port)cwiid from python 2.7 to 3.2.
It uses a lot of deprecated stuff so I have to change a lot of stuff in order to have it work with 3.2. Right now I'm stuck because of a load error. With a python 3.2 environment and the library installed to the package repo I do:
prompt: echo "import cwiid" | python -
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (PyInit_cwiid)
Besides blind searching in the source code, where does python expect the PyInit_cwiid method?
In the source code for example there is the py_plugin.c which contains a py_init method.

Related

I can import module in python but cannot import the same module when using python command in gdb

I have a simple module called mini. It can be imported in either python interactive interpreter or a python .py script. The module is a C extension based so I want to debug it in gdb (version > 7). I learned that gdb has python command to interpret python command or script like:
(gdb) python import mini
However, it failed to import the module by saying:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named mini
I guess it might be the environment setting with either my gdb setting or my linux searching path setting. What will be the possible reason of this problem? Thanks.

ImportError with different python installations.

I am getting below ImportError while running a python file.
ImportError: No module named osgeo.gdal_array
!/usr/bin/env python
from osgeo.gdal_array import BandReadAsArray
However, if i try to import same from command line, it runs fine.
$ which python
/home/hduser/anaconda2/bin/python
$ python
>>> from osgeo.gdal_array import BandReadAsArray
>>>
Also, please see the below where i am getting the same ImportError.
$ /usr/local/bin/python2.7
>>> from osgeo.gdal_array import BandReadAsArray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named osgeo.gdal_array
I figured out that there is something going on between different versions of python. But, i do not want to change the original source code.
How do i make my program run without changing anything within the code of calling python installed in anaconda explicitly?

Error when I install samtools for python on windows

I am trying to install pysam and pybedtools modules on python 3.4. But I got an Error:
Collecting pysam
Using cached pysam-0.9.0.tar.gz
Complete output from command python setup.py egg_info:
'.' is not recognized as an internal or external command,
operable program or batch file.
# pysam: htslib mode is shared
# pysam: htslib configure options: None
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\ikirov.CLO\AppData\Local\Temp\pip-build-_me_xeme\pysam\setup.py", line 212, in <module>
sys.abiflags)]
AttributeError: 'module' object has no attribute 'abiflags'
Could you please help me with it?
Hi I got the same error last year during one of my class.
As I know back then, pysam simply won't work with python3 + windows environment.
See this: https://github.com/pysam-developers/pysam/issues/353 looks like it is still unsolved now.
For my homework, I just used this http://bow.codeplex.com/
And my suggestion, just try to use linux or get a python2. Yes I know the scientific field is the slowest for the 2->3 transition. It sucks.

PyCharm Python ImportError Behave

I'm trying to run some tests in PyCharm using Behave and it keeps telling me I have this issue:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/bin/behave", line 7, in <module>
from behave.__main__ import main
ImportError: No module named behave.__main__
I had a colleague clone the project and they can run it fine on their machine, any insights?
Python 2.7.10
$ pip freeze | grep ehave
behave==1.2.5
The issue is that in Project Interpreter, I was using a different version of Python on my machine that did not have behave installed/included.
From Pycharm settings -> Project -> Python interpreter , search for behave and include it into your ptoject.

'sleepymongoose' is not defined?

I am trying to set up sleepy.mongoose, a mongoDB REST interface using the instructions here.
I am using windows 8, :( ...anyway... I have python 3.3.2 installed and it is accessible from the cmd prompt. I also have pymongo installed, when i enter help('modules') to python, pymongo is on the list of available modules!
But when I try to run python httpd.py from the sleepy.mongoose dir (thanks karthikr), I get an error:
C:\Users\Brook\Desktop\sleepy.mongoose>python httpd.py
Traceback (most recent call last):
File "httpd.py", line 1, in <module>
sleepymongoose/httpd.py
NameError: name 'sleepymongoose' is not defined
Now I tried actually cding into the proper dir, but I get this other error:
C:\Users\Brook\Desktop\sleepy.mongoose\sleepymongoose>python httpd.py
File "httpd.py", line 221
print "\n================================="
^
SyntaxError: invalid syntax
I have had the same problem with Python 2.7 on Windows. Considering 'httpd.py' wich contains only:
sleepymongoose/httpd.py
You need this command line to start it:
python sleepymongoose/httpd.py
You are using python 3 to run python 2 code. The syntax for print amongst other things has changed. Use Python 2 or a server which supports python 3.

Categories