Centos 7 and netsnmp for python 3 - python

I installed python3 on centos 7 since I should start moving my scripts from python 2 to 3.
yum install python3
# rpm -qa |grep python3
python3-libs-3.6.8-13.el7.x86_64
python3-setuptools-39.2.0-10.el7.noarch
python3-pip-9.0.3-7.el7_7.noarch
python3-3.6.8-13.el7.x86_64
I have a script that imports netsnmp and uses it. Works fine under python 2 but does not under python 3.
# rpm -qa |grep python |grep -i snmp
net-snmp-python-5.7.2-48.el7_8.1.x86_64
Under python3 I get this error:
Traceback (most recent call last):
File "up.py", line 52, in <module>
oid = netsnmp.Varbind('.1.3.6.1.2.1.1.5.0')
AttributeError: module 'netsnmp' has no attribute 'Varbind'
Is there a way to get netsnmp working with python 3 under centos 7 with minimal fuss and without breaking things?

Just run.
yum install python2 -y
Then
yum install python36 -y
It should work due to it covered or updates required dependencies.

Related

How to import the library function "import can" in Python

I am using Ubuntu. I want to spam the bus and view the packets using Wireshark. I tried to run the Python code shown below, but it threw the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'can'
My code:
import time, can
bustype = 'socketcan'
channel = 'vcan0'
def producer(id):
# :param id: Spam the bus with messages including the data id.
bus = can.interface.Bus(channel=channel, bustype=bustype)
for i in range(10):
msg = can.Message(arbitration_id=0xc0ffee, data=[id, i, 0, 1, 3, 1, 4, 1], extended_id=False)
bus.send(msg)
# Issue #3: Need to keep running to ensure the writing threads stay alive.
time.sleep(1)
producer(10)
Ubuntu 18.04 and later
In Ubuntu 18.04 and later python-can and python3-can are provided by the default Ubuntu repositories. Open the terminal and type:
sudo apt update
sudo apt install python3-can # for Python 3.x
or
sudo apt update
sudo apt install python python-can # for Python 2.x
To install CANard (Library for interacting with Controller Area Network (CAN)) you must use pip.
python3 -m pip install --user CANard # for Python 3.x
or
python -m pip install --user CANard # for Python 2.x
Whenever you get the no module named '<module_name>' error in Python, it means that python can not find the module. Likely because module is missing.
You can install python modules using pip.
If you don't have the pip tool then you can install it using sudo apt install python-pip on Debian based operating systems.
In your case you need python-can module which can be install by using
pip install python-can
You need to install external third-party package python-can
You can do so using pip. Follow the instructions in the provided link

pip on a Mininet host cant find installed packages

I have Mininet on a VM, I installed a package called wsproto using pip, but when I try to use that package from inside a Mininet host I get an error indicating that the package is missing:
Traceback (most recent call last):
File "examples/http3_server.py", line 10, in <module>
import wsproto
ModuleNotFoundError: No module named 'wsproto'
It turns out that the packages available for the Mininet host are far less than the packages actually installed on the system!
My Question:
How do I install a Python package and make it available for Mininet?
I am running on Ubuntu 20.04, using Python 3.8.10:
$ whereis python3
python3: /usr/bin/python3.8-config /usr/bin/python3 /usr/bin/python3.8 /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz
and on Mininet:
h1 whereis python3
python3: /usr/bin/python3.8-config /usr/bin/python3 /usr/bin/python3.8 /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz
I figured out the solution, I had to use sudo like so:
sudo pip install wsproto
You are trying to compare the string user.type with an unknown variable fetus , you should compare it with the string 'fetus' not with fetus
<div *ngIf="user.type=='fetus'">

Pydoop Installation on CentOS 6

I am trying to install Pydoop (https://crs4.github.io/pydoop/installation.html) on CentOS 6 (Hortonworks HDP physical cluster, 4 nodes). I have Python 3.4 and Python 2.6 installed on my master. When I install it using Python 3 it shows syntax error like below:
[root#abc]# python3 setup.py build
File "setup.py", line 45
print 'using setuptools version', setuptools.__version__
^
SyntaxError: Missing parentheses in call to 'print'
When I install it using Python 2 it shows following error
[root#abc]# python setup.py build
using setuptools version 35.0.2
Traceback (most recent call last):
File "setup.py", line 65, in <module>
import pydoop
File "/root/pydoop/pydoop/__init__.py", line 42, in <module>
_HADOOP_INFO = _PATH_FINDER.find() # fill the cache ASAP
File "/root/pydoop/pydoop/hadoop_utils.py", line 624, in find
info[a] = getattr(self, a)()
File "/root/pydoop/pydoop/hadoop_utils.py", line 433, in hadoop_home
_hadoop_home_from_version_cmd() or
File "/root/pydoop/pydoop/hadoop_utils.py", line 394, in
_hadoop_home_from_version_cmd
output = sp.check_output([hadoop_exec, 'version'])
AttributeError: 'module' object has no attribute 'check_output'
I don't want to upgrade default python from 2.6 to 2.7 as it may break yum which uses python2.6 and upgrading it may cause problems. Any suggestions please?
You can install Python 2.7 and pip on CentOS 6 without breaking yum:
# yum update
# yum install centos-release-SCL epel-release
# yum install python27 python27-devel
# echo ". /opt/rh/python27/enable" >/etc/profile.d/python.sh
# source /etc/profile
# curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
# python get-pip.py
# python --version
Python 2.7.13
# pip --version
pip 9.0.1 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python 2.7)

yum install python-pip:No package python-pip available

After updating python from 2.5 to 2.7.6 in RedHat 4.2, I tried to use yum to install python pip. However, error occurs:
[gz#pl1 ~]$ sudo yum install python-pip
updates-newkey | 2.3 kB 00:00
fedora | 2.1 kB 00:00
updates | 2.6 kB 00:00
Setting up Install Process
Parsing package install arguments
No package python-pip available.
Nothing to do
I wonder why? Some say I should
turn on EPEL repo
first, but how?
Unfortunately, even though I "python get-pip.py" manually, it didn't work either. The error was:
Traceback (most recent call last):
File "get-pip.py", line 7219, in <module>
import bz2
ImportError: No module named bz2
However, bz2 was there
which bzip2-devel
/usr/bin/which: no bzip2-devel in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/gz/bin)
And my reference comes from:
http://www.pip-installer.org/en/latest/installing.html
Thanks for any tip!
I'm going to assume there's a reason you're using RHEL 4.2. In general, you install an RPM to add the EPEL repo although you can also just pull down the repo info file; assuming you're using a 32bit version of RHEL 4.2, I believe you want the one at http://dl.fedoraproject.org/pub/epel/4/i386/epel-release-4-10.noarch.rpm (if you're using 64-bit or powerpc or whatever, I'd suggest going to http://dl.fedoraproject.org/pub/epel/4/ and navigating accordingly)
(So download the RPM, and then install it)

how to install pcap in ubuntu using python

this is my code :
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
recv_len=len(recv_data)
if recv_len == 102 and recv_data[42]== chr(02) and recv_data[101] == chr(03):
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
elif recv_len == 55:
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
and i use this to install pcap :sudo apt-get install python-libpcap , it installed ,
but when i run the code , it show error :
Traceback (most recent call last):
File "weapon.py", line 2, in <module>
import pcap ,struct
ImportError: No module named pcap
what can i do ,
thanks
For me on Ubuntu 10.04 the package is called python-libpcap:
sudo apt-get install python-libpcap
Then when I do:
import pcap
It works great!
I'm guessing the installed module doesn't match the version of python you're running.
Look in /usr/lib/python2.7/dist-packages/ and see if pcap is there (substituting the version you're using for 2.7).
You need to make sure that you have pip installed.
sudo apt-get install python-pip
Then you can install pypcap:
sudo easy_install pypcap
sudo pip install pypcap
I verified it for Ubuntu 14.10.

Categories