Error printing variables while debugging Cython - python

I'm trying to debug some Cython code with gdb that is wrapping C++ code to be called from Python. I followed the instructions in the documentation but I'm getting some errors while debugging that are unrelated to my code. Example:
(gdb) cy print some_variable
Python Exception <type 'exceptions.AttributeError'> 'PyDictObjectPtr' object has no attribute 'items':
Error occurred in Python: 'PyDictObjectPtr' object has no attribute 'items'
I'm also getting this one sometimes (usually after the first one):
Python Exception <class 'gdb.error'> There is no member named ob_sval.:
Error occurred in Python command: There is no member named ob_sval.
To debug the code I created an environment with Docker:
FROM debian
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
build-essential gdb-python2 python-dbg python-dev \
python-pip python-numpy-dbg
RUN pip install cython pygments
CMD bash
I found two related posts in the cython-users google group but with no answer.

An issue was finally opened in Cython (thanks #hygorxaraujo!) and it was identified as a defect:
https://github.com/cython/cython/issues/2699
Pull requests welcome!

Related

free radius python module installation fails on Rocky linux 8.5

I am trying to install free radius(https://github.com/FreeRADIUS/freeradius-server) with python(python2) module on Rocky linux 8.5.
I tried the following installation commands:
(1) yum -y install freeradius
(2) yum -y install freeradius-utils
(3) yum -y install freeradius-python
(1)(2) are good, but (3) shows the following error message on the console:
No match for argument: freeradius-python Error: Unable to find a match: freeradius-python
Also when I key in the "radiusd -X" command for debugging. The console shows the following error message:
etc/raddb/mods-enabled/python[59]: Failed to link to module 'rlm_python': /usr/lib64/freeradius/rlm_python.so: cannot open shared object file: No such file or directory
I wonder if there is any possible way to use free radius with python(python2) module on Rocky linux 8.5 ???
THANKS !!!!

apt - dpkg python-rpi.gpio dependency problems

Every time i try to install something, upgrade or autoremove this error happens!
I've searched the web and tried some fixes but they don't seem to work, I don't have python2.7 installed only 3 and can't install python2 or anything because of this. I've tryed to sudo rm python-rpi.gpio_0.7.0-0.1~bpo10+4_armhf.deb but the file will keep comming. Pls I really need some help since I've got some work on my pi and don't want to get a new image
sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
python-rpi.gpio
The following packages will be upgraded:
python-rpi.gpio
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
18 not fully installed or removed.
Need to get 0 B/20.7 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Reading changelogs... Done
(Reading database ... 152893 files and directories currently installed.)
Preparing to unpack .../python-rpi.gpio_0.7.0-0.1~bpo10+4_armhf.deb ...
/var/lib/dpkg/info/python-rpi.gpio.prerm: 6: /var/lib/dpkg/info/python-rpi.gpio.prerm: pyclean: Too many levels of symbolic links
dpkg: warning: old python-rpi.gpio package pre-removal script subprocess returned error exit status 2
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: pyclean: Too many levels of symbolic links
dpkg: error processing archive /var/cache/apt/archives/python-rpi.gpio_0.7.0-0.1~bpo10+4_armhf.deb (--unpack):
new python-rpi.gpio package pre-removal script subprocess returned error exit status 2
/var/lib/dpkg/info/python-rpi.gpio.postinst: 6: /var/lib/dpkg/info/python-rpi.gpio.postinst: pycompile: Too many levels of symbolic links
dpkg: error while cleaning up:
installed python-rpi.gpio package post-installation script subprocess returned error exit status 2
Errors were encountered while processing:
/var/cache/apt/archives/python-rpi.gpio_0.7.0-0.1~bpo10+4_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
Some notes: I really really don't want to change the SD Card and parcially lose what I have, second I've tried sudo apt-get install -f and sudo apt update --fix-missing when i followed this guide the sudo dpkg --remove --force-remove --reinstreq command was showing this error dpkg: error: unknown force/refuse option 'remove'
As it turns out I still had remainnings of Python2 and Python3 binaries and those were not linked properly by the OS, this means that Python3 was linked to Python2 and vice-versa.
To get it working I had to:
Uninstall the Python2 dependencies
Get the link working correctly
Reinstall Python2 with wget
Verify if all links are working correctly (for Raspbian this means):
python --version links to Python2
python2 --version links to Python2
python3 --version links to Python3
Use the following commands:
sudo dpkg -i --force-overwrite /var/cache/apt/archives//python-rpi.gpio_0.7.0-0.1~bpo10+4_armhf.deb
Still have the same problem, use:
sudo mv /var/lib/dpkg/info/python-rpi.gpio.* /tmp/
sudo dpkg --remove --force-remove-reinstreq python-rpi.gpio
A typo in your command sudo dpkg --remove --force-remove --reinstreq isn't valide. The correct option is --force-remove-reinstreq. See dpkg --force-help.

How to use transform_graph to optimize Tensorflow model

I used to use the optimize_for_inference library in optimizing frozen Tensorflow models. However, I have read from different sources that Tensorflow no longer supports it.
I came across transform_graph, and its documentation is found here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#strip_unused_nodes
At first, I ran into errors and found out that I need to install Tensorflow from source (https://www.tensorflow.org/install/install_sources#install_the_pip_package) instead of using PIP.
I already re-installed Tensorflow from source, and ran this code in bash (/tensorflor/tensorflow dir):
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=tensorflow_inception_graph.pb \
--out_graph=optimized_inception_graph.pb \
--inputs='Mul' \
--outputs='softmax' \
--transforms='
strip_unused_nodes(type=float, shape="1,299,299,3")
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
round_weights(num_steps=256)'
And ran to again this error:
-bash: bazel-bin/tensorflow/tools/graph_transforms/transform_graph: No such file or directory
What seems to be the problem?
That is weird.
The code I write below is to install and using the transform_graph in CentOS7.
yum install epel-release
yum update
yum install patch
curl https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -o /etc/yum.repos.d/vbatts-bazel-epel-7.repo
yum install bazel
curl -L -O https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz
cd tensorflow-1.8.0
./configure # interactive!
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph
After you install the Tensorflow by source code and finish the configure, the bazel codes should be working.
The error from you environment is occurred when you didn't finish the install the Tensorflow by source code, or you ran the script in wrong path.
Please check the configure step, path of the Tensorflow root.

letsencrypt failed with ImportError: No module named interface

I'm using Amazon linux, and I followed some steps for using letsencrypt that easily found in google search, but all it fails with:
Error: couldn't get currently installed version for /root/.local/share/letsencrypt/bin/letsencrypt:
Traceback (most recent call last):
File "/root/.local/share/letsencrypt/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/certbot/main.py", line 11, in <module>
import zope.component
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/zope/component/__init__.py", line 16, in <module>
from zope.interface import Interface
ImportError: No module named interface
What I do is:
# git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
# /opt/letsencrypt/letsencrypt-auto --debug
That's it. So I tried to fix this, but dozens of solution that I found all won't worked to me.
Most of them said try this:
unset PYTHON_INSTALL_LAYOUT
But still got same error, nothing changes. And someone said that type this:
pip install --upgrade pip
But after typed that, I can't use pip anymore, it failed with some kind of command not found error, so I had recreated my server again.
I also tried to use CertBot, but it gives me exactly same error!
I'm using Linux 4.4.51-40.58.amzn1.x86_64 x86_64, need a help. I spent almost a day, but nothing progressed.
Every solution that I was found were not worked to me. Any advice will very appreciate it.
Removing certbot directory did the trick for me.
rm -rf /opt/eff.org/certbot/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo ./certbot-auto certonly --standalone -d example.com --no-bootstrap
I had same issue and after a long run, a very simple thing solved this issue on my AWS instance:
Move the letsencrypt cache files to another folder (considering you run it as root/sudo):
sudo mv /root/.local/share/letsencrypt /root/.local/share/letsencrypt-old
Downloaded a brand new version of letsencrypt
git clone https://github.com/letsencrypt/letsencrypt
Run the letsencrypt command to test if its working again:
sudo ./letsencrypt-auto --debug
During my search for a solution I also updated pip which might have helped. Although my attempts after pip update did not solved my issue in the same way as cleaning up the letsencnrypt cache folder.
I hope this helps. If not, some links I can share about same issue:
certbot zope.interface error
no module named interface
letsencrypt failed with no module named interface
Part of the issue for me was related to some strange default behavior around 64 bit packages installing, but not being picked up by python. After getting this issue [it's mostly installed at this point], run the following
cd /root/.local/share/letsencrypt
\cp -r ./venv/lib64/* ./venv/lib/
Then retry the command. The install locations of the python virtual environment change with different versions and operating systems, but the general principle has helped me debug two different installs.
I have also faced this issue multiple times and every time I have to repeat these following steps:
Remove cache:
sudo rm -rf /root/.local/share/letsencrypt/
sudo rm -rf /opt/eff.org/certbot/`
then,
unset PYTHON_INSTALL_LAYOUT
Install Let’s Encrypt by cloning the github repository into /opt/letsencrypt
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
then run installer again
/opt/letsencrypt/letsencrypt-auto --debug
these steps always works for me.
I solved it following the next steps
Download certbot-auto by going to this link.
Delete letsencrypt folder:
sudo rm -rf /opt/eff.org/
Install cryptography module:
sudo python -m pip install cryptography
Run certbot-auto --debug
sudo ./certbot-auto --debug

How to install pysqlite?

I am trying to install pysqlite (Python interface to the SQLite). I downloaded the file with the package (pysqlite-2.5.5.tar.gz). And I did the following:
gunzip pysqlite-2.5.5.tar.gz
tar xvf pysqlite-2.5.5.tar
\cd pysqlite-2.5.5
python setup.py install
At the last step I have a problem. I get the following error message:
error: command 'gcc' failed with exit status 1
I found that other peoples also had this problem.
As far as I understood in the person had a problem because sqlite2 was not installed. But in my case, I have sqlite3 (I can run it from command line).
May be I should change some paths in "setup.cfg"? At the moment I have there:
#define=
#include_dirs=/usr/local/include
#library_dirs=/usr/local/lib
libraries=sqlite3
define=SQLITE_OMIT_LOAD_EXTENSION
And if I type "which sqlite3" I get:
/usr/bin/sqlite3
I saw a similar question here. The answer was "you need sqlite3-dev". But, even if it is the case, how to check if I have sqlite3-dev. And if I do not have it how to get it?
Can anybody pleas help me with that problem.
Thank you in advance.
For Debian distros I fixed this problem with
sudo apt-get install libsqlite3-dev
I was able to resolve the same build error by installing the sqlite-devel package:
sudo yum install sqlite-devel
I had the same problem, I'm using python 2.4, neither sqlite3-dev nor libsqlite3-dev are available for CentOS.
yum install python-devel
seems to solve the issue.
how to check if I have "sqlite3-dev"
That's entirely dependent on what Linux distro you're using -- is it Fedora, Suse, Ubuntu, Gentoo, Mandrake, or which other one out of the dozens out there; there are several packaging strategies and tools used to check which packages are there, get more, and so forth.
So, never ask questions about checking, getting or tweaking packages on Linux without specifying the distribution[s] of interest -- it makes it essentially impossible to offer precise, specific help.
Edit: the simplest way I know of getting details about your Linux distribution (works on all the ones I have at hand to try, but I don't have a particularly wide array...;-):
$ cat /etc/*-release
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.2"
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
...etc, etc...
This is probably going to be the contents of file /etc/lsb-release, but I'm suggesting the *-release because I think there may be some other such files involved.
Of course, if the need to check your distro applies inside a file or program, reading this file (or files) and locating specific contents will also be quite feasible; but for the purpose of informing would-be helpers about what distro you're using, the cat at the shell prompt is going to be quite sufficient;-).
What version of Python do you have? SQLite is integrated in Python since 2.5:
http://docs.python.org/library/sqlite3.html
If you insist on compiling it yourself, the package is called sqlite3-devel, you can find it e.g. here
You could use yum or apt-get instead
first type :
sudo yum(or apt-get) search python-sqlite3
you will get something like python-sqlite3dbm.noarch
then type :
sudo yum(or apt-get) install python-sqlite3dbm.noarch
this way your os will install all you need for you and you wont get errors
I had following compile errors on CentOS release 5.6:
src/cache.h:34: error: expected specifier-qualifier-list before 'PyObject_HEAD'
src/cache.h:44: error: expected specifier-qualifier-list before 'PyObject_HEAD'
src/cache.h:61: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pysqlite_NodeType'
src/cache.h:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pysqlite_CacheType'
src/cache.h:64: error: expected declaration specifiers or '...' before 'PyObject'
src/cache.h:64: error: expected declaration specifiers or '...' before 'PyObject'
src/cache.h:67: error: expected declaration specifiers or '...' before 'PyObject'
src/cache.h:67: error: expected declaration specifiers or '...' before 'PyObject'
Installing python-devel helped me too:
yum install python-devel
I'm the one who answered the other question :) On systems that use RPM packages, i.e. you normally use 'yum' to install things, the package is named sqlite3-devel.
On most Debian based systems (i.e. you use apt-get to install packages), the package is named sqlite3-dev.
This is a very typical difference between the two, most other packages follow the same naming convention.
I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.
Did you install the python sqlite lib?
sudo apt-get install python-sqlite
you need to install the plug in http://yum.baseurl.org/download/yum-metadata-parser/
wget -c "http://yum.baseurl.org/download/yum-metadata-parser/yum-metadata-parser-1.1.4.tar.gz"
then install it
tar zxf yum-metadata-parser-1.1.4.tar.gz && cd yum-metadata-parser-1.1.4
/path/to/python setup.py install

Categories