Numpy & Matplotlib suddenly cannot be imported in Hydrogen although it works fine in the Terminal
See original GitHub issueDescription
Numpy & Matplotlib suddenly cannot be imported in Hydrogen in Atom although it works fine in the Terminal
Steps to Reproduce
I’m regularly importing Numpy
and Matplotlib
with Hydrogen
. 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 also enter the following line in the Terminal:
atom --clear-window-state
but it didn’t help either
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 also posted
Expected behavior: I want to be able to import package in a python script
Actual behavior: I get a message of the form ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
Reproduces how often: it varies, but it come and goes without a clear time pattern. I also cannot tell why it comes at a certain point. It seems to happen with matplotlib
and numpy
Versions
python 3.6.5
macOS 10.13.4
Atom 1.26.1 x64
Hydrogen 2.4.1
Additional Information
When the problem happens, Atom seems to want to connect to a previously used script in which numpy was used, to open numpy itself
Please let me know if something is not clear or if more informations are needed
I first posted this issue on the Github page of Atom https://github.com/atom/atom/issues/17375 but the maintainers told me that it was probably a problem regarding Hydrogen
so this is why I’m writing you
Many thanks in advance for your time!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Try running
conda env list
and make sure you have the env you expect active. Right now it looks like you have the root environment active (based on the kernelspec). This means you will need the packages installed within that environment.Additionally, you will need to make sure the environment you want is active in atom’s environment. If you start atom from the command line (recommended), the env that is active in your terminal should be passed to atom and you will have access to packages installed in that env.
@BenRussert:
This is the output of
conda env list
Now I ran
import numpy
I get the error:
If the error comes from the root environment or the path to it, how can I fix it? shall I change the path? and if yes from where: Atom? Terminal?
Many thanks in advance and sorry for that probably very basic question