I am attempting to carry out lens correction and I've fallen at the first hurdle. After running the following code, I receive this error...
#Install required packages
!pip install opencv-python
import cv2
import numpy as np
import pathlib
!pip install chessboard
from chessboard import calibrate_chessboard
from utils import load_coefficients, save_coefficients
KeyError Traceback (most recent call last)
<ipython-input-19-0a40b3424bef> in <module>()
6 import pathlib
7 get_ipython().system('pip install chessboard')
----> 8 from chessboard import calibrate_chessboard
9 from utils import load_coefficients, save_coefficients
2 frames
/usr/local/lib/python3.7/dist-packages/chessboard/benchmark.py in Benchmark()
105 ('machine', platform.machine()),
106 # CPU.
--> 107 ('cpu_vendor', cpu_info['vendor_id']),
108 ('cpu_model', cpu_info['brand']),
109 ('cpu_freq_actual', cpu_info['hz_actual'][0]),
KeyError: 'vendor_id'
Can anyone help with this please?
It looks like that you are using outdated package chessboard, not updated since 2017, repo now archived.
It rely on another package py-cpuinfo. There is this issue. The key vendor_id is now replaced with vendor_id_raw. Note that setup.py for chessboard does not specify version for py-cpuinfo, so I guess you use the latest one.
One way to solve the problem is to use specific older version of py-cpuinfo before that change. The latest version of py-cpuinfo with vendor_id is 5.0.0. The latest version before latest chessboard release date is 3.3.0
Another option is to try and replace key vendor_id with vendor_id_raw everywhere inside chessbeoard package.
My preference would be with the second option as chessboard is no longer developed. In any case be aware there might be other issues or unwanted behaviour.
Related
I´m using Python 3 and I´m working in jupyter, when I try to import qiskit the following error is showed:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-578b7f7e9727> in <module>
----> 1 import qiskit
~\AppData\Roaming\Python\Python36\site-packages\qiskit\quantum_info\synthesis\two_qubit_decompose.py in __init__(self, unitary_matrix)
169 # D, P = la.eig(M2) # this can fail for certain kinds of degeneracy
170 for i in range(100): # FIXME: this randomized algorithm is horrendous
--> 171 state = np.random.default_rng(i)
172 M2real = state.normal()*M2.real + state.normal()*M2.imag
173 _, P = la.eigh(M2real)
AttributeError: module 'numpy.random' has no attribute 'default_rng'
I got almost the same error as:
AttributeError: module 'numpy.random' has no attribute 'default_rng'
with the numpy version of '1.16.2'
numpy.__version__
'1.16.2'
As a solution, either you need to put these lines at the top of your file:
import numpy
numpy.random.bit_generator = numpy.random._bit_generator
Or the your current numpy version probably is <= 1.17. Hence, you need to update the NumPy version. For instance, I have updated it on Anaconda environment as:
conda update numpy
And the current version is:
numpy.__version__
'1.19.2'
Updates take time because of lots of dependencies of NumPy. Hopefully, the issue is resolved on my side!
You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs
if you're using jupyter in anaconda - uninstalling, reinstalling and restarting the kernel worked for me similar here: AttributeError: module 'numpy' has no attribute '__version__'
!pip uninstall -y numpy
!pip install numpy
RESTART KERNEL
I was trying to work with skyfield and I got the error that:
"ModuleNotFoundError: No module named 'jplephem.pck'"
I get the error in the first line itself
it goes like this:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-3a2b53f77cba> in <module>
----> 1 from skyfield.api import load
2
3 planets = load('de421.bsp')
4 earth, mars = planets['earth'], planets['mars']
5
~\Anaconda3\lib\site-packages\skyfield\api.py in <module>
12 from .errors import DeprecationError
13 from .iokit import Loader, load_file
---> 14 from .planetarylib import PlanetaryConstants
15 from .positionlib import position_from_radec
16 from .starlib import Star
~\Anaconda3\lib\site-packages\skyfield\planetarylib.py in <module>
3 import re
4 from numpy import array, cos, einsum, nan, rollaxis, sin
----> 5 from jplephem.pck import DAF, PCK
6 from .constants import ASEC2RAD, AU_KM, DAY_S, tau
7 from .functions import rot_x, rot_y, rot_z
ModuleNotFoundError: No module named 'jplephem.pck'
I tried to look it up on the net and it said that it is a dependency and I do not know what to do to debug this
from skyfield.api import load
planets = load('de421.bsp')
earth, mars = planets['earth'], planets['mars']
ts = load.timescale()
t = ts.now()
position = earth.at(t).observe(mars)
ra, dec, distance = position.radec()
print(ra)
print(dec)
print(distance)
Any form of help will be appreciated
Did you install Skyfield with pip install skyfield, or through another mechanism? Current versions of Skyfield have a setup.py that insists on a recent version of jplephem because only versions more recent than 2.11 will have the pck module that Skyfield needs. The pip install tool should have detected this, but if it did not, doing pip install -U jplephem to force an update of jplephem should get you going again!
Workaround
If you are using conda, you will be installing an old version. Try:
conda uninstall jplephem
pip install -U jplephem
Real solution
The long-term solution is for the conda folks to get their packaging of this library working again. The list of pull requests on their "feedstock" for the library looks like it has encountered repeated failures to build and distribute an up-to-date package:
But the most recent PR is hand-written and has asked for moderator attention, so hopefully things will get fixed.
I am new to ROS and python. This question could be silly but spent almost 5 hours on this. I am using PyCharm (Latest version) with Python 2.7.15 64 bit (Also tried with 3.x). I need to import a few libraries as below:
import roslib;
roslib.load_manifest('smach_tutorials')
import rospy
import smach
import smach_ros
However, PyCharm fails to identify roslib, rospy, smach and smach_ros (could not find in the interpreter also to import). The above libraries are example given in the official site:
http://wiki.ros.org/smach/Tutorials/Simple%20State%20Machine
OS: Windows 7 (64 bit)
ROS not installed: ("SMACH is a ROS-independent Python library to build hierarchical state machines" - from the official site)
Error Traceback:
Traceback (most recent call last):
File "C:/Users/****/Desktop/Python/TestCharm.py", line 3, in <module>
import roslib;
ModuleNotFoundError: No module named 'roslib'
If you are using the catkin version of ROS (Groovy and later), it does not use the manifest file but uses the package.xml file instead.
So your code will be:
import rospy
import smach
Apparently, your code is ready for ROS Fuerte or earlier version.
With supposing that Smach is ROS-independent, you need only to the import smach
Thanks for all the support. I found out it is not possible for my perticular case to use SMACH because it has dependency on catkin. I am using Windows 7 and should be upgraded to windows 10 or use Ununtu Linux.
I recently installed the enthoughts distribution of python and started to go through the examples as outlined here
http://www.enthought.com/products/epdgetstart.php?platform=mac
i.e.
EPD comes with a number of examples to get you started. To run the scripts in the Examples subdirectories, simply launch IPython and type run .
I executed the following and received a run time error which I'm not sure how to interpret as I am a new to python and enoughts.
mycomputer:demo$ ipython
In [1]: run multiaxis_using_Plot.py
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo/multiaxis_using_Plot.py in <module>()
14 from scipy.special import jn
15
---> 16 from chaco.example_support import COLOR_PALETTE
17 # Enthought library imports
18 from enable.api import Component, ComponentEditor
/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/chaco/example_support.py in <module>()
47 pass
48 else:
---> 49 raise RuntimeError("Can't load wx or qt4 backend for Chaco.")
50
51
RuntimeError: Can't load wx or qt4 backend for Chaco.
In [2]:
In [2]: pwd
Out[2]: u'/Library/Frameworks/EPD64.framework/Versions/7.1/Examples/chaco-4.0.0/demo'
Any insights on what might be going on? I greatly appreciate it.
User 'minrk' answered this question:
As described on the 64bit EPD download page, several GUI toolkits (definitely Wx, and I think Pyglet as well) are not functional when run in 64bit mode on EPD on OS X. It is recommended that if you want to use the GUI tools on OSX, you use 32bit EPD. – minrk
I'm having trouble figuring out an error message in Python.
yesterday, I've installed python using the latest EPD package, and wxPython2.9 using the wxPython2.9-osx-cocoa-py2.7 package for Mac OS.
I then added wx to my PYTHONPATH.
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/wx-2.9.1-osx_cocoa
export PYTHONPATH=$WXDIR
export PYTHONPATH=$PYTHONPATH:$WXDIR/tools
but when I try to run stuff I get this error:
In [14]: import matplotlib.pyplot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/imrisofer/Documents/third/hddm-read-only/hddm/<ipython console> in <module>()
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
93
94 from matplotlib.backends import pylab_setup
---> 95 new_figure_manager, draw_if_interactive, show = pylab_setup()
96
97 #docstring.copy_dedent(Artist.findobj)
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/__init__.py in pylab_setup()
23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
24 backend_mod = __import__(backend_name,
---> 25 globals(),locals(),[backend_name])
26
27 # Things we pull in from all backends
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wxagg.py in <module>()
21
22 from backend_agg import FigureCanvasAgg
---> 23 import backend_wx # already uses wxversion.ensureMinimal('2.8')
24 from backend_wx import FigureManager, FigureManagerWx, FigureCanvasWx, \
25 FigureFrameWx, DEBUG_MSG, NavigationToolbar2Wx, error_msg_wx, \
/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py in <module>()
43 import wxversion
44 except ImportError:
---> 45 raise ImportError(missingwx)
46
47 # Some early versions of wxversion lack AlreadyImportedError.
ImportError: Matplotlib backend_wx and backend_wxagg require wxPython >=2.8
I can successfully import wx, so I don't no what's the problem.
Am I missing anything in the PYTHONPATH?
In Ubuntu 12.04, this problem can be solved by running the command
sudo apt-get install libjpeg62
I realize this may not be useful here, but I wanted to document it somewhere on teh interwebz so I can find it when I run into this problem again myself which will undoubtedly happen.
I'm using Ubuntu 13.10, Canopy 1.2, and PyCharm 3.0.2. When trying to use matlablib, it always complains "Matplotlib backend_wx and backend_wxagg require wxPython >=2.8".Pretty sure that I'm using wxPython 2.8. Then I tried all the methods described in this page, but neither of them works for me.
It turns out that it can be solved by modifying matplotlibrc file. There is a line:
backend : WXAgg
In fact we can change the backend to whatever we like, and I change it to TKAgg, which works just fine for me.
Select your wx version before importing any wx modules
import wxversion
wxversion.select('2.8')
The above code should come before import wx
This happened to me on a Windows x64 installation that did not install wxversion.py in the site-packages directory (c:\Python27\Lib\site-packages by default).
You can get a copy of wxversion.py from the WX svn repository:
http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/wxversion/wxversion.py?content-type=text%2Fplain&view=co
this link helped me
https://support.enthought.com/entries/22601196-wxPython-2-8-and-2-9
Here's how I fixed the problem, which I hope will be useful for others in future
In Terminal: gedit Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
Edit the line "backend : WXAgg" into "backend : QtAgg"
Save and exit
I just ran into this myself. One potential cause of this (quite unhelpful) error message is if you installed wx as a single-version installation (INSTALL_MULTIVERSION=0 when running setup.py). In this case, the module wxversion does not get built (or installed) and as such matplotlib incorrectly assumes that all of wx is missing.
This currently is the default setting in installations by the homebrew version of wxWidgets (wxmac) with the option --python.
In your case (albeit a year and a half late), you'd need to ensure that wxversion.py exists within /usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages/. If it doesn't, you'd need to recompile wx with the above flag set. Otherwise you just need to set your $PYTHONPATH such that it includes the base site-packages directory, too:
export WXDIR=/usr/local/lib/wxPython-2.9.1.1/lib/python2.7/site-packages
export PYTHONPATH=$WXDIR:$WXDIR/wx-2.9.1-osx_cocoa:$WXDIR/wx-2.9.1-osx_cocoa/tools
I've solved with this:
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I solved this by setting the backend to MacOSX in ~/.matplotlib/matplotlibrc:
backend : MacOSX
I've solved this on Windows by looking in the site packages folder in the python library. In there, there should be another folder titled site-packages. In this subfolder, there is the wxversion library. If you copy this library into the Lib folder in python, this import error should be averted.
sudo apt-get install python-wxtools
Install it. Worked for me.