0

I'm regularly importing Matplotlib Numpy PySide2 in Atom. They unexpectedly cannot be import for an unknown reason and then appear to be again re-importable, again unexplained.

When trying to import matplotlib with the following command

import matplotlib.pyplot as plt

This scripts runs without problems when I run in a Jupyter notebook or through the Terminal. But When trying to run on Hydrogen in Atom, I get the following error message:

File "<ipython-input-3-3dc8365ef973>", line 6
ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
                             ^
SyntaxError: invalid syntax

I get the same error with Pyside2 when trying to run the line

from PySide2.QtWidgets import QApplication, QLabel

I get the error message

ModuleNotFoundError: No module named 'PySide2.QtWidgets'; 'PySide2' is not a package

Here is the path of python (after having typed which python in the Terminal): /anaconda3/bin/python

I checked that the matplotlib is installed by running the command conda list in the Terminal and got (among all the other packages) those lines:

matplotlib 2.1.2 py36h6d6146d_0
matplotlib 2.2.2 <pip>
PySide2 5.9.0a1.dev1525348214

I tried to run the following command in the Terminal but didn't solve the problem

sudo apt-get install python3-matplotlib sudo pip3 install matplotlib

I had a similar issue with numpy when trying to import import numpy. Although import numpy was not a problem an hour ago, I get now the following error message (it seems it wants to connect to a previously used script in which numpy was used, to open numpy itself):

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-5-592c151f282b> in <module>()
      1 # from numpy import genfromtxt as gft
----> 2 import numpy

~/Downloads/numpy.py in <module>()
----> 1 from numpy import genfromtxt
      2 my_data = genfromtxt('/Users/mymac/Documents/PyQt/image_viewer/csv_file_generator/eggs.csv',
      3     delimiter=',',
      4     dtype=None,
      5     encoding=None)

ImportError: cannot import name 'genfromtxt'

I had the same issue when tryin to import opencv2: I got the following error message:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import--------------------------- 
------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-8f6675581547> in <module>()
      5 from PySide2.QtCore import *
      6 from PySide2.QtGui import *
----> 7 import cv2
      8 import numpy
      9 import csv

ImportError: numpy.core.multiarray failed to import

I visited the following site which didn't help me (or I didn't understand how to implement exactly the steps to fix the problem)

ImportError: No module named matplotlib.pyplot

Importing matplotlib.pyplot in atom editor

matplotlib Error: No module named matplotlib even though it is installed

I'm running on/with python 3.6.5 macOS 10.13.4 Atom 1.27.0 x64 Hydrogen 2.4.1

ecjb
  • 5,169
  • 12
  • 43
  • 79
  • You need to make sure that matplotlib is installed in the Anaconda environment that you are using. Have you checked that? – IonicSolutions May 11 '18 at 07:52
  • Thank you @IonicSolutions. I checked that the matplotlib is installed by running the command `conda list` in the Terminal and got those 2 lines: `matplotlib 2.1.2 py36h6d6146d_0` and `matplotlib 2.2.2 `. By the way, if i can run Jupyter Notebook, doesn’t that automatically mean that the package is installed in anaconda? – ecjb May 11 '18 at 08:04
  • I cannot understand why but I could import matplotlib for a few hours in Atom but then the problem resurfaced and received again the error message when trying to import matplotlib – ecjb May 12 '18 at 15:53
  • I am getting similar performance. A code I run a lot will run just fine in the morning say but not run in the afternoon, the first line in my code is 'import numpy as np'. The error message says 'no module numpy'. I'll keep trying to run it and eventually it will run. – Natsfan May 30 '18 at 00:05
  • hello for your comment @jmh. If that problem to be solved, we need to get the attention of somebody who can solve the problem. I'm unfortunately not such a person otherwise I would have solve the problem. To get the attention of that person, you can 1. upvote that question and 2. write a comment on github on the issue I opened regarding that problem: https://github.com/nteract/hydrogen/issues/1315 – ecjb May 30 '18 at 07:04

0 Answers0