Error when installing anaconda3 and attempting import matplotlib.pyplot in bash on windows

Asked 1 years ago, Updated 1 years ago, 72 views

[Symptoms]
Installing anaconda3 in bash on windows and running the matplotlib demo file dete_demo.py results in an error.

[Procedure]
● lxrun/uninstall, lxrun/install
● bash Anaconda3-4.2.0-Linux-x86_64.sh
● python-V# Python 3.5.2::Anaconda 4.2.0 (64-bit)
● python date_demo.py## Appended error 1

行ったResponse 対応
Do I have to install PyQt4 because it says No module named 'PyQt4'?
● conda list | greppyqt##pyqt5.6.0py35_0
● conda list | grep PyQt4## None
● conda search PyQt4##None
● pipsearchPyQt4##PyQt4(4.11.4) was in the list
● pip install PyQt4##Attachment error 2
● pip install --upgrade pip
● pip install PyQt4## Appended Error 3

I've done it three times, but it was the same symptom

Please let me know if you have any tips or advice.

WindowsAnaconda3 for Windows displays the graph correctly.

[Additional note, what I did after that]
stackoverflow.com had a page for the same symptom.
Is pyqt5 the cause...?
We have taken the last step.

conda install-ypyqt=4.11

Now there are no more errors for PyQt4, but

A new libSM.so.6 error occurred.
There was a page on stackoverflow.com for the same symptom, so we took action.

 apt-get install libsm6 libxrender1 libfontconfig1

Now the above error is gone, but

RuntimeError: Invalid DISPLAY variable appears.orz

As the display cannot be displayed, we decided to save the graph as an image as a short-term response.
※ date_demo.py See correction code

However, the image is not saved. (Tears) orz *The image will be saved with the same code in the Windows version.

So far...

(Appended error 1)

$python date_demo.py
Traceback (most recent call last):
File "date_demo.py", line 16, in <module>
  import matplotlib.pyplot asplt
File"/mnt/c/Users/Admin/.BashHome/anaconda3/lib/python 3.5/site-packages/matplotlib/pyplot.py", line 114, in<module>
_backend_mod, new_figure_manager, draw_if_interactive, _show=pylab_setup()
File"/mnt/c/Users/Admin/.BashHome/anaconda3/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line32, impylab_setup
globals(), locals(), [backend_name], 0)
File"/mnt/c/Users/Admin/.BashHome/anaconda3/lib/python 3.5/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
  from.backend_qt5import QtCore
File"/mnt/c/Users/Admin/.BashHome/anaconda3/lib/python 3.5/site-packages/matplotlib/backends/backend_qt5.py", line 31, in<module>
  from.qt_compatimport QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File"/mnt/c/Users/Admin/.BashHome/anaconda3/lib/python 3.5/site-packages/matplotlib/backends/qt_compat.py", line 137, in<module>
  from PyQt4 import QtCore, QtGui
ImportError: No module named 'PyQt4'

(Appended error 2)

$pip install PyQt4
Collecting PyQt4
Could not find a version that satiffies the requirement PyQt4 (from versions:)
No matching distribution found for PyQt4
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install -- upgrade pip' command.

(Appended Error 3)

$pip install PyQt4 
Collecting PyQt4
Could not find a version that satiffies the requirement PyQt4 (from versions:)
No matching distribution found for PyQt4

date_demo.py Modification Code

#!/usr/bin/env python

import datetime
import numpy as np
import matplotlib as mpl## Add
mpl.use('Agg')## Add
import matplotlib.pyplot asplt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook

years=mdates.YearLocator() #everyyear
months=mdates.MonthLocator()#every month
yearsFmt=mdates.DateFormatter('%Y')

datafile=cbook.get_sample_data('goog.npy')
try:
    r=np.load(dataafile, encoding='bytes') .view(np.recarray)
except TypeError:
    r=np.load(datafile).view(np.recarray)

config,ax=plt.subplots()
ax.plot(r.date,r.adj_close)

ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(yearsFmt)
ax.xaxis.set_minor_locator(months)

datemin = datetime.date(r.date.min().year, 1, 1)
datemax = datetime.date(r.date.max().year+1,1,1)
ax.set_xlim(datemin, datemax)

def price(x):
    return'$%1.2f'%x
ax.format_xdata=mdates.DateFormatter('%Y-%m-%d')
ax.format_ydata=price
ax.grid (True)

config.autofmt_xdate()

config.savefig('date_demo.py.png')## Add

# plt.show()##Comment out

[Environment]
Windows 10
bash on windows
anaconda3-4.2.0

$conda info
Current conda install:

               platform —Linux-64
          conda version: 4.2.13
       conda is private —False
      conda-env version: 4.2.13
    conda-build version: 2.0.2
         python version: 3.5.2.final.0
       requests version: 2.11.1
       root environment: /mnt/c/Users/Admin/.BashHome/anaconda3 (writable)
    default environment: /mnt/c/Users/Admin/.BashHome/anaconda3
       envs directories: /mnt/c/Users/Admin/.BashHome/anaconda3/envs
          package cache: /mnt/c/Users/Admin/.BashHome/anaconda3/pkgs
           channel URLs: https://repo.continuum.io/pkgs/free/linux-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/pro/linux-64
                          https://repo.continuum.io/pkgs/pro/noarch
            config file —None
           offline mode —False

python windows-10 matplotlib anaconda wsl

2022-09-30 19:28

1 Answers

As of November 26, 2016, I received the following report.

Now that I've solved it myself, I'd like to write it down for those with the same symptoms.

●anaconda3 Installation
● conda install nomkl
● sudo apt-get install x11-apps
● Install xming and launch Xming.exe in Windows 10

Test Code

import matplotlib as mpl
mpl.use('tkagg')
import matplotlib.pyplot asplt
import numpy as np

x = np.range (-3,3,0.1)
y = np.sin(x)
plt.plot(x,y)
plt.savefig('test.png')
plt.show()

The PyQt4 error has not been resolved, but matplotlib is now able to save and display images of graphs.


2022-09-30 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.