Using Ubuntu Python packages and ImportError: No module named - python

How to install Ubuntu's packaged modules instead of using pip?
All Python packages tell us to do the packages installation via pip, but Ubuntu has its own packaging system. I'd rather stick to using the system default packaging system instead of cooking my own using pip, but is that a good idea?
Searching for "ImportError: No module named" you'll get all kinds of such error for all kinds of different Python modules. I'm wondering if there is a general solution to use Ubuntu system default packaging system instead.
Specifically, I installed python-jsonpath-rw with
sudo apt-get install python-jsonpath-rw
but when I tried to do
import sys, json, jsonpath
I get:
Traceback (most recent call last):
File "./pyjsonpath", line 2, in <module>
import sys, json, jsonpath
ImportError: No module named jsonpath
I then searched, and found
http://blog.ingensol.pl/2015/03/need-to-make-quick-json-fixes-jsonpath.html
and followed all its commands,
$ sudo apt-get install python-jsonpath-rw
$ sudo apt-get install python-setuptools
$ sudo easy_install -U jsonpath
but am still getting the exact same errors as before.
Please help. Thx.
$ apt-cache policy python-jsonpath-rw
python-jsonpath-rw:
Installed: 1.4.0-2
Candidate: 1.4.0-2
Version table:
*** 1.4.0-2 500
500 http://ca.archive.ubuntu.com/ubuntu zesty/main amd64 Packages
500 http://ca.archive.ubuntu.com/ubuntu zesty/main i386 Packages
100 /var/lib/dpkg/status
$ dpkg -L python-jsonpath-rw
/.
/usr
/usr/bin
/usr/bin/python2-jsonpath
/usr/lib
/usr/lib/python2.7
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/jsonpath_rw
/usr/lib/python2.7/dist-packages/jsonpath_rw/__init__.py
/usr/lib/python2.7/dist-packages/jsonpath_rw/bin
/usr/lib/python2.7/dist-packages/jsonpath_rw/bin/__init__.py
/usr/lib/python2.7/dist-packages/jsonpath_rw/bin/jsonpath.py
/usr/lib/python2.7/dist-packages/jsonpath_rw/jsonpath.py
/usr/lib/python2.7/dist-packages/jsonpath_rw/lexer.py
/usr/lib/python2.7/dist-packages/jsonpath_rw/parser.py
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info/PKG-INFO
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info/dependency_links.txt
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info/entry_points.txt
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info/requires.txt
/usr/lib/python2.7/dist-packages/jsonpath_rw-1.4.0.egg-info/top_level.txt
/usr/share
/usr/share/doc
/usr/share/doc/python-jsonpath-rw
/usr/share/doc/python-jsonpath-rw/changelog.Debian.gz
/usr/share/doc/python-jsonpath-rw/copyright
$ python -c "import sys, pprint; pprint.pprint(sys.path)"
['',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/local/lib/python2.7/dist-packages/jsonpath-0.75-py2.7.egg',
'/usr/lib/python2.7/dist-packages']

Related

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'">

Install ROS Kinetic on MacOS under a separate Anaconda environment

I'm installing ROS Kinetic on MacOS Sierra 10.12.6 under a seperate environment under Python Anaconda distribution.
Here is my python version(my seperate python environment in Anaconda is called "ros-kinetic"):
(ros-kinetic) jizhe#jizhedeMacBook-Pro  ~/ros_catkin_ws  python --version
Python 3.6.4 :: Anaconda, Inc.
I followed the guide: http://wiki.ros.org/kinetic/Installation/OSX/Homebrew/Source.
When I execute the "rosdep install" command, I got the following error:
(ros-kinetic) jizhe#jizhedeMacBook-Pro ~/ros_catkin_ws  rosdep install --from-paths src --ignore-src --rosdistro kinetic -y
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
actionlib: No definition of [python-wxtools] for OS [osx]
catkin: No definition of [google-mock] for OS [osx]
roslisp: No definition of [google-mock] for OS [osx]
Obviously, there is something wrong with the package "python-wxtools" and "google-mock".
I've already install the wxpython via "brew install wxpython", and here is the wxpython info:
(ros-kinetic) jizhe#jizhedeMacBook-Pro  ~/ros_catkin_ws  brew info wxpython
wxpython: stable 3.0.2.0 (bottled)
Python bindings for wxWidgets
https://www.wxwidgets.org/
/usr/local/Cellar/wxpython/3.0.2.0_1 (1,108 files, 37.9MB) *
Poured from bottle on 2018-02-24 at 03:56:21
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/wxpython.rb
==> Dependencies
Required: wxmac ✔
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/jizhe/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/jizhe/Library/Python/2.7/lib/python/site-packages/homebrew.pth
And I've already run the command:
$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ echo "$(brew --prefix)/lib/python2.7/site-packages" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
So, what's wrong with the package "google-mock" and "python-wxtools", how can I solve this problem?
Try installing with --skip-keys python-wxtools --skip-keys google-mock. It worked for me.
There is a ticket for this issue. Basically the workaround is to install googletest manually. Not sure what's wrong with python-wxtools.
edit: If you're using ros-install-osx, you can add the following lines to your rosdeps.yaml file:
google-mock:
osx:
homebrew:
packages: []
I found this question from a Google search, just for your information in 2021 installing ROS in conda also on macOS should be much straightforward, see the following links:
https://medium.com/robostack/cross-platform-conda-packages-for-ros-fa1974fd1de3
https://github.com/RoboStack/ros-noetic

'EntryPoint' object has no attribute 'resolve' when using Google Compute Engine

I have an issue related to Cryptography package in Python. Can you please help in resolving these, if possible ? (tried a lot, but couldnt figure out the exact solution)
The python code which initiates this error:
print("Salt: %s" % salt)
server_key = pyelliptic.ECC(curve="prime256v1") # ----->> Line2
print("Server_key: %s" % server_key) # ----->> Line3
server_key_id = base64.urlsafe_b64encode(server_key.get_pubkey()[1:])
http_ece.keys[server_key_id] = server_key
http_ece.labels[server_key_id] = "P-256"
encrypted = http_ece.encrypt(data, salt=salt, keyid=server_key_id,
dh=self.receiver_key, authSecret=self.auth_key) # ----->> Line8
Value of "Salt" is getting displayed in 100% of the cases.
If Line3 gets executed successfully, I see the the following EntryPoint Error because of http_ece.encrypt() call (Line8):
AttributeError("'EntryPoint' object has no attribute 'resolve'",)
(Ref. File Link: https://github.com/martinthomson/encrypted-content-encoding/blob/master/python/http_ece/init.py#L128 )
Requirements.txt(partial):
cryptography==1.5
pyelliptic==1.5.7
pyOpenSSL==16.1.0
On Running the command: sudo pip freeze --all |grep setuptools, I get:
setuptools==27.1.2
Please let me know if any more detail is required.
This problem seems to be basically due to some Old/Incompatible packages(related to PyElliptic, Cryptography, PyOpenSSL and/or setuptools) installed on the VM. For Reference: https://github.com/pyca/cryptography/issues/3149
Can someone please suggest a good solution to resolve this issue completely ?
Thanks,
The issue referenced in c66303382 has this traceback (you never gave your traceback so I have to assume yours ends the same way):
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
_default_backend = MultiBackend(_available_backends())
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
"cryptography.backends"
The full line that triggers the error looks like this:
_available_backends_list = [
ep.resolve()
for ep in pkg_resources.iter_entry_points(
"cryptography.backends"
)
]
Searching the repository for EntryPoint definition, then blaming pkg_resources/__init__.py where it is reveals that pkg_resources.EntryPoint.resolve() was added in commit 92a553d3adeb431cdf92b136ac9ccc3f2ef98bf1 (2015-01-05) that went into setuptools v11.3.
Thus you'll see this error if you use an older version.
Ran Following Commands from the project path /opt/projects/myproject-google/myproject and it resolved the Attribute EntryPoint Error Issue:
(Assuming project virtual env path as: /opt/projects/myproject-google/venv)
Command: (from path: /opt/projects/myproject-google/myproject)
export PYTHONPATH= # [Blank]
sudo pip install --upgrade virtualenv setuptools
sudo rm -rf ../venv
sudo virtualenv ../venv
source ../venv/bin/activate
sudo pip install --upgrade -r requirements.txt
deactivate
Running the above commands upgraded the virtual environment & the setuptools version inside the virtual Env. located at path: /opt/projects/myproject-google/venv/lib/python2.7/site-packages. To test if setuptools have upgraded successfully, try some of these commands:
Command: sudo virtualenv --version
Output: 15.0.3
Command: echo $PYTHONPATH
Output: [blank]
Command: python -c 'import pkg_resources; print(pkg_resources.__file__)'
Output: ~/.local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
Command: python -c 'import sys; print(sys.path)'
Output: ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '~/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/opt/projects/myproject-google/myproject', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
Command: ls /opt/projects/myproject-google/venv/lib/python2.7/site-packages
Output:
easy_install.py pip pkg_resources setuptools-27.2.0.dist-info wheel-0.30.0a0.dist-info
easy_install.pyc pip-8.1.2.dist-info setuptools wheel
Command: python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())'
Output: <cryptography.hazmat.backends.multibackend.MultiBackend object at 0x7ff83a838d50>
Command /opt/projects/myproject-google/venv/bin/python -c 'from cryptography.hazmat.backends import default_backend; print(default_backend())'
Output
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named cryptography.hazmat.backends
Command: /opt/projects/myproject-google/venv/bin/python -c "import pkg_resources; print(pkg_resources.__file__)"
Output: /opt/projects/myproject-google/venv/local/lib/python2.7/site-packages/pkg_resources/__init__.pyc
Ref Link: https://github.com/pyca/cryptography/issues/3149
These Steps resolved the Attribute EntryPoint Issue completely with an updated version of cryptography package & the setuptools.
Update As on 15 September 2016, The Cryptography Team has again added the workaround for supporting old packages too.
(Ref. Link: https://github.com/pyca/cryptography/issues/3150 )

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)

Installing Graphviz on Os X 10.5.8

I'm trying to install Graphviz 2.14.1 on osX 10.5.8
I installed Graphviz from the Universal Binary here:
http://www.ryandesign.com/graphviz/
$ svn co https://networkx.lanl.gov/svn/pygraphviz/trunk pygraphviz
- Fingerprint: 43:8e:fa:75:00:60:67:07:fd:04:3c:e7:bf:25:86:fd:66:b3:f6:cb
(R)eject, accept (t)emporarily or accept (p)ermanently? t
A pygraphviz/pygraphviz
A pygraphviz/pygraphviz/graphviz.i
A pygraphviz/pygraphviz/graphviz.py
A pygraphviz/pygraphviz/tests
A pygraphviz/pygraphviz/tests/graph.txt
A pygraphviz/pygraphviz/tests/attributes.txt
A pygraphviz/pygraphviz/tests/__init__.py
A pygraphviz/pygraphviz/tests/test.py
A pygraphviz/pygraphviz/tests/layout_draw.txt
A pygraphviz/pygraphviz/graphviz_wrap.c
A pygraphviz/pygraphviz/__init__.py
A pygraphviz/pygraphviz/release.py
A pygraphviz/pygraphviz/agraph.py
A pygraphviz/INSTALL.txt
A pygraphviz/doc
A pygraphviz/doc/source
A pygraphviz/doc/source/contents.rst
A pygraphviz/doc/source/examples.rst
A pygraphviz/doc/source/static
A pygraphviz/doc/source/static/contents.png
A pygraphviz/doc/source/static/navigation.png
A pygraphviz/doc/source/static/sphinxdoc.css
A pygraphviz/doc/source/static/empty.txt
A pygraphviz/doc/source/tutorial.rst
A pygraphviz/doc/source/conf.py
A pygraphviz/doc/source/install.rst
A pygraphviz/doc/source/download.rst
A pygraphviz/doc/source/reference
A pygraphviz/doc/source/reference/news.rst
A pygraphviz/doc/source/reference/credits.rst
A pygraphviz/doc/source/reference/related.rst
A pygraphviz/doc/source/reference/api_notes.rst
A pygraphviz/doc/source/reference/history.rst
A pygraphviz/doc/source/reference/agraph.rst
A pygraphviz/doc/source/reference/legal.rst
A pygraphviz/doc/source/reference/faq.rst
A pygraphviz/doc/source/reference/index.rst
A pygraphviz/doc/source/templates
A pygraphviz/doc/source/templates/layout.html
A pygraphviz/doc/source/templates/indexsidebar.html
A pygraphviz/doc/source/templates/index.html
A pygraphviz/doc/sphinxext
A pygraphviz/doc/sphinxext/only_directives.py
A pygraphviz/doc/Makefile
A pygraphviz/setup.py
A pygraphviz/setup_egg.py
A pygraphviz/setup_extra.py
A pygraphviz/MANIFEST.in
A pygraphviz/README.txt
A pygraphviz/examples
A pygraphviz/examples/miles.py
A pygraphviz/examples/simple.py
A pygraphviz/examples/star.py
A pygraphviz/examples/django_simple.py
A pygraphviz/examples/subgraph.py
A pygraphviz/examples/attributes.py
A pygraphviz/examples/miles_dat.txt.gz
A pygraphviz/setup.cfg
U pygraphviz
Checked out revision 1947.
Bryan#bryan-wheelocks-macbook-pro-15 Tue Dec 21 07:25:18 ~/Downloads
$ cd pygraphviz/
Bryan#bryan-wheelocks-macbook-pro-15 Tue Dec 21 07:25:22 ~/Downloads/pygraphviz
$ python setup.py install
Trying pkg-config
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
Trying dotneato-config
Failed to find dotneato-config
Your graphviz installation could not be found.
Either the graphviz package is missing on incomplete
(binary packages graphviz-dev or graphviz-devel missing?).
If you think your installation is correct you will need to manually
change the include_path and library_path variables in setup.py to
point to the correct locations of your graphviz installation.
The current setting of library_path and include_path is:
library_path=None
include_path=None
Traceback (most recent call last):
File "setup.py", line 78, in <module>
raise OSError,"Error locating graphviz."
OSError: Error locating graphviz.
Here is the path to Graphviz:
$ ls -la /usr/local/lib/
drwxrwxr-x 40 root wheel 1360 Dec 21 06:22 graphviz
$ python setup.py install --library_path /usr/local/lib/graphviz/
Trying pkg-config
/bin/sh: pkg-config: command not found
/bin/sh: pkg-config: command not found
Trying dotneato-config
Failed to find dotneato-config
Your graphviz installation could not be found.
Either the graphviz package is missing on incomplete
(binary packages graphviz-dev or graphviz-devel missing?).
If you think your installation is correct you will need to manually
change the include_path and library_path variables in setup.py to
point to the correct locations of your graphviz installation.
The current setting of library_path and include_path is:
library_path=None
include_path=None
Traceback (most recent call last):
File "setup.py", line 78, in <module>
raise OSError,"Error locating graphviz."
OSError: Error locating graphviz.
I was unsuccessful in finding the binary packages graphviz-dev or graphviz-devel
What do I need to do to get this installed?
It seems like you are missing the "pkg-config" package. You can install it with Homebrew
brew install pkg-config
2.14.1 is a very old version of graphviz. You may have better success using the official OS X installer package for 2.26 (at this writing) here. Then you will likely need to edit the pygraphiz setup.py to use the proper library_path and include_path. Most likely you will need to uncomment the /usr/local/lib/graphviz and usr/local/include/graphviz versions but use ls /usr/local to find out for sure.
On the other hand, with so many dependent libraries and packages involved, this is a perfect case for using a 3rd-party package manager like MacPorts which will manage all of the dependencies for you and allow you to easily update as new releases become available. Once you have installed the base MacPorts files, you can install it all with:
$ sudo port selfupdate
# either
$ sudo port install py26-pygraphviz # with MacPorts python2.6
# ... or
$ sudo port install py27-pygraphviz # with MacPorts python2.7
As Ned said,
Locate your setup.py file for graphviz. In my case, it was located at /Users/*my_username*/build/pygraphviz/setup.py
Finally, uncomment the lines corresponding to the Mac OSX paths for library_path and include_path. These are the lines containing: /usr/local/lib/graphviz and usr/local/include/graphviz

Categories