Failing at first hurdle using pcapng in python 3.8; unable to import FileScanner SOLVED I had one line too many - python-3.8

This is my first attempt at writing python code; I think I'm using 3.8.5. Ironically, I have many versions of python installed, and maybe that is where I'm going wrong. But I don't see it.
Everywhere I look, the very first line of code I find is from pcapng import FileScanner but I cannot get it to work. <EDIT 'pip install pcapng' is the problem />
$ pip install pcapng
Requirement already satisfied: pcapng in /home/bryan/.local/lib/python3.8/site-packages (0.1.25)
$ pip install python-pcapng
Requirement already satisfied: python-pcapng in /home/bryan/.local/lib/python3.8/site-packages (1.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from python-pcapng) (1.14.0)
$ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
$ python --version
Python 3.8.10
$ python ./ReadWireSharkPoC.py
Traceback (most recent call last):
File "./ReadWireSharkPoC.py", line 4, in <module>
from pcapng import FileScanner
ImportError: cannot import name 'FileScanner' from 'pcapng' (/home/bryan/.local/lib/python3.8/site-packages/pcapng/__init__.py)
coding
import pcapng
help(pcapng)
gives me
Help on package pcapng:
NAME
pcapng
DESCRIPTION
# Copyright 2017 Brocade Communications Systems, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
PACKAGE CONTENTS
block
block_test
blocks
codec
const
constants (package)
exceptions
linktype
mrt
mrt_test
option
option_test
pen
scanner
structs
tlv
tlv_test
util
util_test
utils
FILE
/home/bryan/.local/lib/python3.8/site-packages/pcapng/__init__.py
Where am I going wrong?

It seems that my naive attempt to install Python's pcapng with
pip install pcapng
was fundamentally flawed. It should just be
pip install python-pcapng

Related

CuPy on AMD GPU causing an ImportError

I'm trying to use/test the (experimental) AMD GPU support of CuPy (8.1.0). In short: I'm having an ImportError.
I followed the instructions for installing ROCm on a Ubuntu focal machine (with a gfx906/Radeon VII (Vega 20) card).
From the doc I set the mentioned variables (with adjusted HCC_AMDGPU_TARGET), the ROCM_HOME and export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin.
pip3 install -v --no-cache-dir cupy succeeded without any complaints. Just a few compiler notes and warnings because of the -v option
Now when I try to import cupy it's throwing an ImportError.
In [1]: import cupy
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/cupy/__init__.py in <module>
19 message='can\'t resolve package from __spec__')
---> 20 from cupy import core # NOQA
21 except ImportError as e:
/usr/local/lib/python3.8/dist-packages/cupy/core/__init__.py in <module>
----> 1 from cupy.core import core # NOQA
2 from cupy.core import internal # NOQA
3
cupy/core/core.pyx in init cupy.core.core()
cupy/core/_routines_manipulation.pyx in init cupy.core._routines_manipulation()
cupy/core/_routines_indexing.pyx in init cupy.core._routines_indexing()
cupy/core/_routines_math.pyx in init cupy.core._routines_math()
cupy/core/_reduction.pyx in init cupy.core._reduction()
cupy/core/_cub_reduction.pyx in init cupy.core._cub_reduction()
ModuleNotFoundError: No module named 'cupy.cuda.cub'
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
<ipython-input-1-329ec5cf1bc8> in <module>
----> 1 import cupy
/usr/local/lib/python3.8/dist-packages/cupy/__init__.py in <module>
39 original error: {}'''.format(_exc_info[1])) # NOQA
40
---> 41 raise ImportError(_msg) from e
42
43
ImportError: CuPy is not correctly installed.
If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
$ pip freeze
If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
$ pip install cupy --no-cache-dir -vvvv
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
original error: No module named 'cupy.cuda.cub'
What should I do next? What should I look for in the compilation process? Thanks in advance
EDIT On request here the complete stdout and stderr of the installation process and a few io's of the console: https://seafile.cloud.uni-hannover.de/d/68862cd1057e47d180aa/
To summarize the discussion in the comments so far:
For CuPy v8.x (the latest stable releases): Up to v8.1 the offending cupy.cuda.cub module is not built in ROCm/HIP environments, which will hopefully be fixed in v8.2 (see ticket).
For CuPy v9.x (the master branch): It should just work as long as rocPRIM and hipCUB are correctly installed. It's likely that the OP's local environment is not correctly set up, leading to cupy.cuda.cub module not built and thus ImportError.

Netmiko - Windows 10 - SSH Router - Not able to run 1st command only

>>> from netmiko import ConnectHandler
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\netmiko\__init__.py", line 7, in <module>
Hello Experts,
Post applying from netmiko import ConnectHandler command I am getting above error.
Setup - Windows 10, Python 3.7, Netmiko installed. no other file present in pc with name netmiko.py.
Please suggest solution.
In order to use Netmiko, you need to be in the same python environment that you installed netmiko.
I see you installed Windows 10 and Python 3.7, but the python that is being used to call Netmiko is 2.7. You can tell from the "Python27" in the directory name C:\Python27\lib\site-packages\netmiko\__init__.py.
Run a Python 3.7 shell and try the command again. Make sure Netmiko is properly installed in the environment.
To verify if netmiko is installed, type help("modules") to retrieve a list of all installed packages. If Netmiko was properly installed, you should see it there.
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")
Please wait a moment while I gather a list of all available modules...
---- output omitted ----
Cryptodome bdb gc pyexpat
__future__ binascii genericpath pygments
_string codecs netaddr tabnanny
_strptime codeop netapp tarfile
_struct collections netmiko telnetlib
_symtable colorama netmiko_globals tempfile
_testbuffer colorsys netrc terminal_server
_testcapi compileall nntplib test
_testconsole concurrent nt textfsm
_testimportmultiple configparser ntpath textwrap
_testmultiphase contextlib nturl2path this
_textfsm contextvars numbers threading
I hope this was helpful
Run : python3 to access python version 3.5+ terminal.
>>>from netmiko import ConnectHandler

caffe cmake error:ImportError: No module named numpy

My configuration:
Ubuntu 16.04 64bit
Python 2.7.9
Caffe 1.0.0
under ipython,I can import numpy and use it,but when following this:
mkdir build
cd build
cmake ..
I got error:
- Found PythonInterp: /usr/local/bin/python2.7 (found suitable version "2.7.9", minimum required is "2.7")
-- Found PythonLibs: /usr/local/lib/libpython2.7.a (found suitable version "2.7.9", minimum required is "2.7")
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy
-- Could NOT find NumPy (missing: NUMPY_INCLUDE_DIR NUMPY_VERSION) (Required is at least version "1.7.1")
-- Boost version: 1.58.0
and I am sure only one numpy is installed,so anyone tell me how to solve this problem?
Don't know whether you have fixed it.
I met the issue as well, I have done several steps, here's what I did
# because I use anaconda, about line 74, I comment out the line like
ANACONDA_HOME := /data/software/miniconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/envs/caffe/include \
$(ANACONDA_HOME)/envs/caffe/include/python3.6m \
$(ANACONDA_HOME)/envs/caffe/lib/python3.6/site-packages/numpy/core/include
# And I use python3 and I follow the https://yangcha.github.io/Caffe-Conda3/
cmake -DBLAS=open -D python_version=3 ..
Hopes work you out

python tensorflow module dependency on glibc

I successfully build bazel and tensorflow from the source code, but when using the tensorflow module I am getting the following error:
./new_python/bin/python
>>>import tensorflow as tf
Error MSG: File "/home/niraj/Ansible/new_python/lib/python2.7/site-packages/‌​tensorflow/python/py‌​wrap_tensorflow.py", line 28, in <module> _pywrap_tensorflow = swig_import_helper()
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home/niraj/Ansible/new_python/lib/python2.7/site-packages/t‌​ensorflow/python/_py‌​wrap_tensorflow.so)
I am using RHEL6 machine. Any idea how to fix this ?
I found two bug reports on github regarding this very problem
https://github.com/tensorflow/tensorflow/issues/110
https://github.com/bazelbuild/bazel/issues/760
At least I get the impression that getting tensorflow to work on RHEL 6 is at least 'difficult' - as some claim in those two bugreports that they got it to work, with some limitations - if not, at least for now, impossible.
At least for Ubuntu 12.04 and CentOS 6.7 there are solutions. The 2nd answer (mentions CentOS) should work on RHEL 6 as well.
Old/First answer:
According to the link I gathered from this answer, RHEL 6 ships with libc 2.12, not 2.14.
You would have to compile the tensorflow stuff again and link it to an existing libc 2.14 on your system. I'm not quite sure how you were able to compile it without already having libc 2.14 somewhere on your system.
What made the trick for me was updating glibc (in my case to 2.17 version) by:
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-common-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-devel-2.17-55.el6.x86_64.rpm
wget http://copr-be.cloud.fedoraproject.org/results/mosquito/myrepo-el6/epel-6-x86_64/glibc-2.17-55.fc20/glibc-headers-2.17-55.el6.x86_64.rpm
sudo rpm -Uvh glibc-2.17-55.el6.x86_64.rpm \
glibc-common-2.17-55.el6.x86_64.rpm \
glibc-devel-2.17-55.el6.x86_64.rpm \
glibc-headers-2.17-55.el6.x86_64.rpm --force --nodeps
I link original answer

Unable to import matplotlib._png (pylab)

I am unable to import matplotlib._png:
import matplotlib._png as _png ImportError:
/home/james/opt/python/virtualenvs/work/lib/python2.7/site-packages/matplotlib-1.3.x-py2.7-linux-x86_64.egg/matplotlib/_png.so:
undefined symbol: png_set_longjmp_fn
This error prevents me from running import pylab (sincce this ultimately imports matplotlib._png).
I installed matplotlib from source, and made sure to add the path with local installations (/home/james/local) to basedir in setupext.py before running python setup.py install.
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.7.1]
dateutil: yes [using dateutil version 2.1]
tornado: yes [using tornado version 3.0.1]
pyparsing: yes [using pyparsing version 1.5.7]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found Using local copy.]
freetype: yes [version 16.0.10]
png: yes [version 1.2.10]
My research so far:
As can be seen above, matplotlib seems to find version 1.2.10 even though the version that I have under /home/james/local is 1.6.2:
$ find . -iname '*libpng*'
./libpng16.so.16.1.0
./libpng16.so
./libpng16.so.16
./libpng16.a
./libpng.a
./libpng.so
./libpng16.la
./pkgconfig/libpng.pc
./pkgconfig/libpng16.pc
./libpng.la
More specifically, I modified the following line in setupext.py with:
return basedir_map.get(sys.platform, ['/home/james/local', '/usr/local', '/usr'])
but matplotlib seems to have found the system version:
$ locate libpng
/usr/lib/libpng.so
/usr/lib/libpng.so.3
/usr/lib/libpng.so.3.10.0
/usr/lib/libpng12.a
/usr/lib/libpng12.so
/usr/lib/libpng12.so.0
/usr/lib/libpng12.so.0.10.0
Could this be the problem? Why am I unable to import matplotlib._png?
Update:
Looking at setupext.py, it looks like python setup install queries pkg-config through the SetupPackage method _check_for_pkg_config to determine the version of libpng I have installed. It turns out that pkg-config is returning the system installation:
$ pkg-config --libs libpng
-lpng12
even though I have updated basedir in matplotlib's setupext.py, and LD_LIBRARY_PATH to make them point to the the more recent version of libpng that I have locally installed.
Any ideas on how to have pkg-config return the right version?
It's a pkg-config issue; matplotlib's installation is (unfortunately, or perhaps not) relying too much on pkg-config's output.
Assuming you have build libpng the normal way, there should be a pkgconfig subdirectory in your /home/james/local/lib, which contains libpng.pc (and libpng16.pc). When setupext.py runs pkg-config, the latter should of course try and pick up the correct .pc file for libpng. For that, use the PKG_CONFIG_PATH variable and point it to the pkgconfig subdirectory:
$ export PKG_CONFIG_PATH=/home/james/local/lib/pkgconfig
Then, install matplotlib again, and see that it now finds the correct libpng version:
$ python setup.py build
basedirlist is: ['/usr/local', '/usr']
============================================================================
BUILDING MATPLOTLIB
matplotlib: 1.1.0
python: 2.7.4 (default, Apr 8 2013, 16:36:47) [GCC 4.4.5]
platform: linux2
REQUIRED DEPENDENCIES
numpy: 1.7.0
freetype2: 12.0.6
OPTIONAL BACKEND DEPENDENCIES
libpng: 1.6.1
Tkinter: Tkinter: 81008, Tk: 8.4, Tcl: 8.4
(For me, with a different PKG_CONFIG_PATH of course. Yes, I may want to upgrade some dependencies.)
Note that I didn't even alter basedirlist; it's just at its default.
In case pkg-config fails to now pick up some other package, just add more directories to PKG_CONFIG_PATH with colons in between. But I guess this should be enough.
Try
export LD_LIBRARY_PATH=/home/james/local/lib
and then execute Matplotlib... that would point matplotlib to your local version.