I'm assigned to run a python script, that imports several module
#filename: animate_vid_v6.py
import numpy as np
import pandas as pd
import imageio
from trackviz import animate
import sys
from matplotlib.patches import Circle
from operator import itemgetter
import colorsys
after I installed all the required modules, I get this error message.
Traceback (most recent call last):
File "<some_directories>\animate_vid_v6.py", line 4, in <mo
dule>
from trackviz import animate
File "C:\Python39\lib\site-packages\trackviz\animate.py", line 9, in <module>
from trackviz.tools import FigureAxes
File "C:\Python39\lib\site-packages\trackviz\tools.py", line 3, in <module>
from mpl_toolkits.axes_grid1 import Divider, LocatableAxes, Size
ImportError: cannot import name 'LocatableAxes' from 'mpl_toolkits.axes_grid1' (
C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1\__init__.py)
After I scrutinize that message, it is turn out that the LocatableAxes is no longer exists in scripts inside the C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1 directory.
As you can see here, at the C:\Python39\lib\site-packages\mpl_toolkits\axes_grid1\__init__.py, there are no LocatableAxes module.
from . import axes_size as Size
from .axes_divider import Divider, SubplotDivider, make_axes_locatable
from .axes_grid import Grid, ImageGrid, AxesGrid
from .parasite_axes import host_subplot, host_axes
Does anybody has an idea /suggestions to fix this problem? thanks.
The LocatableAxes classes have been deprecated in Matplotlib 3.0.0, but it seems trackviz hasn't been updated since then to avoid using these classes. Indeed, the trackviz GitHub repository hasn't been updated for about three years.
If you really want to use trackviz you will have to install an older version of Matplotlib.
Related
I am trying to import matplotlib in .ipynb file but its not working, none of my files have the same name as _docstring yet I get this error and if I try something in .py file, it works fine.
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
I'm running this in a .ipynb file in VS Code
Output :
ImportError Traceback (most recent call last)
Cell In[3], line 2
1 import numpy as np
----> 2 import matplotlib.pyplot as plt
3 import cv2 as cv
File c:\Users\P****\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py:113
109 from packaging.version import parse as parse_version
111 # cbook must import matplotlib only within function
112 # definitions, so it is safe to import from it here.
--> 113 from . import _api, _version, cbook, _docstring, rcsetup
114 from matplotlib.cbook import sanitize_sequence
115 from matplotlib._api import MatplotlibDeprecationWarning
ImportError: cannot import name '_docstring' from partially initialized module 'matplotlib' (most likely due to a circular import) (c:\Users\P****\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\__init__.py)
But if I try to import matplotlib in .py file like
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(1,10,0.1)
y = x**2
plt.plot(x,y)
plt.show()
It runs fine, no issues.
Try deleting matplotlib folder and reinstalling it.
Full path: AppData\Roaming\Python\Python39\site-packages\matplotlib
It worked for me.
I am trying to run a .py script on my Manjaro box and I keep getting the following error:
[keithm#home2 python]$ python3 gspppff.py
['/home/keithm/bin/python', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/keithm/.local/lib/python3.8/site-packages', '/usr/lib/python3.8/site-packages']
Traceback (most recent call last):
File "gspppff.py", line 7, in <module>
import matplotlib.pylot as plt
ModuleNotFoundError: No module named 'matplotlib.pylot'
Here's the script:
#!/usr/bin/python
import datetime as dt
import sys
print(sys.path)
import matplotlib.pylot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
# graph style
style.use('ggplot')
start = dt.datetime(2020, 1, 1)
end = dt.datetime.now()
# dataframe
df = web.DataReader("TSLA", 'morningstar', start, end)
print(df.head())
I included print(sys.path) to see where python was looking for the mods and I made sure matlablib was installed in both locally: /home/keithm/.local/lib/python3.8/site-packages and in /usr/lib/python3.8/site-packages, but still no change.
The package name is "pyplot", not "pylot". Here is the corrected code:
import matplotlib.pyplot as plt
It's spelled "pyplot", not "pylot".
import matplotlib.pyplot as plt
try "pyplot" you have incorrect spelling
When I run this program in Python, it show me this error:
ImportError: No module named skimage.io.
I have already run the command pip install scikit-image, but I still get this error. Can you please help me?
This is my code:
import matplotlib.pyplot as plt
import skimage.io as io
import skimage.color as color
parrots = io.imread('C:\Python27\Example\parrots.bmp')
parrots_hsv= skcolor.convert_colorspace(parrots, 'RGB','HSV')
fig, ax= plt.subplots(nclos = 2, figsize=('8,4'))
ax[0].imshow(parrots)
ax[0].set_title('original image')
restored_image =skcolore.convert_colorspace(parrots_hsv, 'HSV','RGB')
ax[1].imshow(restored_image)
ax[1].set_title('restored image')
plt.show()`enter code here`
I reproduced this error like so:
import math.sqrt as sq
print(sq(4))
Error:
File ".\Solution.py", line 1, in <module>
import math.sqrt as sq
ModuleNotFoundError: No module named 'math.sqrt'; 'math' is not a package
repaired by:
from math import sqrt as sq
print(sq(4))
So I presume if you changed your imports to the below code it might fix it:
from matplotlib import pyplot as plt
from skimage import io as io
from skimage import color as color
In addition, you might want to read a bit here for a simple explanation about imports.
import numpy as np
import matplotlib.pyplot as plt
def main():
x = np.arange(0, 5, 0.1)
y = np.sin(x)
plt.plot(x, y)
if __name__ == '__main__':
main()
Traceback (most recent call last):
File
"/Users/tim/workspace/Python/MachineLearn/test.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 63, in pylab_setup
[backend_name], 0)
File "/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 11, in <module>
from datalore.display import display
File "/Applications/PyCharm.app/Contents/helpers/pycharm_display/datalore/display/__init__.py", line 1, in <module>
from .display_ import *
File "/Applications/PyCharm.app/Contents/helpers/pycharm_display/datalore/display/display_.py", line 5, in <module>
from urllib.parse import urlencode
ImportError: No module named parse
Process finished with exit code 1
=================
Python: 2.7.16
PyCharm Professional: 2019.2
=================
btw, the code run in console mode is work
Simple answer: disable "show plots in scientific window" (Settings -> Tools -> Python Scientific) or downgrade the PyCharm or move your project to python3
Remember to add plt.show() in your code.
A little more complicated. You need to write own importing hooks to find that urllib.parse and urllib.request (next line in display_.py file are requested. More you can read here https://xion.org.pl/2012/05/06/hacking-python-imports/
(i'm not enough familiar with python 2 import system to write it)
For python 2 use
from urlparse import urlparse
If you need to write code which is Python2 and Python3 compatible you can use the following import
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
In your PyCharm project:
press Ctrl+Alt+s to open the settings
on the left column, select Project Interpreter
on the top right there is a list of python binaries found on your system, pick the right one
eventually click the + button to install additional python modules, in your case, it is parse module is missing so install that one
As mentioned by #Grzegorz Bokota, the problem is coming from the "scientific view mode" of PyCharm. This mode allows to visualise graphs and is thus calling matplotlib, and probably an incompatible version of it if you are using Python 2. This bug has been identified here and it seems that we just have to wait for the next release to get it solved.
I just install pybinding and I'm trying to run the first example that is proposed in the documentation of this library.
import pybinding as pb
import numpy as np
import matplotlib.pyplot as plt
import pybinding as pb
d = 0.2 # [nm] unit cell length
t = 1 # [eV] hopping energy
# create a simple 2D lattice with vectors a1 and a2
lattice = pb.Lattice(a1=[d, 0], a2=[0, d])
lattice.add_sublattices(
('A', [0, 0]) # add an atom called 'A' at position [0, 0]
)
lattice.add_hoppings(
# (relative_index, from_sublattice, to_sublattice, energy)
([0, 1], 'A', 'A', t),
([1, 0], 'A', 'A', t)
)
lattice.plot()
plt.show()
I have already installed what is required in the documentation (for Windows OS) and the sicrpt run pretty well until it has to do the lattice.plot() throwing the following error
Traceback (most recent call last):
File "prueba.py", line 25, in <module>
lattice.plot()
File "C:\xampp7\Python\lib\site-packages\pybinding\lattice.py", line 463, in plot
axes=axes))
File "C:\xampp7\Python\lib\site-packages\pybinding\results.py", line 598, in plot
plot_sites(self.positions, self.sublattices, **props['site'])
File "C:\xampp7\Python\lib\site-packages\pybinding\system.py", line 285, in plot_sites
from pybinding.support.collections import CircleCollection
File "C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py", line 2, in <module>
from matplotlib.collections import Collection, allow_rasterization
ImportError: cannot import name 'allow_rasterization'
I have already check and matplotlib is correctly installed (I try some plots recommended in the documentation of matplotlib and worked pretty well). Also a looked for the file collections.py in the pybinding library and the mistake is in the second line
import numpy as np
from matplotlib.collections import Collection, allow_rasterization
And looking at collections.py of the matplolib and searching for 'allow_rasterization' I found the duplicated 6 time the following function
#artist.allow_rasterization
def draw(self, renderer):
I am pretty new at python so I'm don't know if I'm looking at what I should. Thanks in advance
I got the same issue. I'm using Linux and the package pybinding are installed on
/usr/lib/python3.6/site-packages/pybinding/support/
You can correct the error changing the import modules of allow_rasterization module, changing the file colletion.py
/usr/lib/python3.6/site-packages/pybinding/support/colletion.py
the firsts lines from
import numpy as np
from matplotlib.collections import Collection, allow_rasterization
to
import numpy as np
from matplotlib.collections import Collection
from matplotlib.artist import allow_rasterization
You can correct the plot issue related to previous versions on matplotlib 1.1.2, because now the pybinding packages use matplotlib 2.2.2.
I uninstalled version 2.2.2 of matplotlib and installed version 1.1.2 of marplotlib.
I am now able to do put.show()
go into the file "C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py" and modify the command line as:
"from matplotlib.collections import Collection#, allow_rasterization
from matplotlib.artist import allow_rasterization"
Go into the directory:
~/miniconda3/lib/python3.7/site-packages/pybinding/support
In the file: collections.py
change line 2:
from matplotlib.collections import Collection, allow_rasterization
to
from matplotlib.collections import Collection
from matplotlib.artist import allow_rasterization