I am trying to import pandas in an ipython (2.2.0, running python 3.3.5) notebook in my browser, which fails with
[...]
/usr/local/lib/python3.3/site-packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/usr/local/lib/python3.3/site-packages/numpy/lib/__init__.py in <module>()
15 from .ufunclike import *
16
---> 17 from . import scimath as emath
18 from .polynomial import *
19 #import convertcode
ImportError: cannot import name scimath
However, in both pure python and non-notebook ipython, import pandas and the problematic line of from numpy.lib import add_newdoc run without a problem, and the file /usr/local/lib/python3.3/site/site-packages/numpy/lib/scimath.py exists and has the same permissions and creation date as the __init__.py in the same directory.
How do I debug this error? What does ipython notebook change about imports as compared to cli ipython?
See this previous question and answer - https://stackoverflow.com/a/15622021/1766755.
A key difference between the IPy notebook and CLI is the default behavior of the os.path var, as well as the notebook setting notebook_dir.
Obviously in the IPy notebook, pandas is not finding the scimath module. If you look closely at the traceback, you'll see the line
17 from . import scimath as math
This is a relative path import, the . signifying a request to import a module from the same directory. Depending on where the CLI is begun vs where you tell IPython to think it's running from, this could be the cause of numpy not finding scimath. I could be wrong, but it's happened to me before.
Related
Im getting below error while importing pandas
cannot import name 'nosetester'
Traceback (most recent call last):
File "/usr/bin/anaconda/envs/py35/lib/python3.5/site-packages/pandas/init.py", line 56, in
from pandas.util.nosetester import NoseTester
File "/usr/bin/anaconda/envs/py35/lib/python3.5/site-packages/pandas/util/nosetester.py", line 13, in
from numpy.testing import nosetester
ImportError: cannot import name 'nosetester'
Pandas version ->0.18.1
Numpy version ->1.18.0
Any help to resolve the error?
One approach is to use python 3.6 version like 3.6.5 is a stable version.
Another approach is if you want to continue in python 3.5 version itself then python 3.5.2 it worked correctly.
I am trying to create and save an stl file with a cube and I cannot import the mesh module for some reason. When hovering over mesh, it says: "Cannot find 'mesh' in '__init__.py'" I originally had the directory folder named stlExperiments but then someone said you cannot have stl in the name so I changed all instances of "stl" to "st" and no change, so I'm left to assume it's a completely different problem. Can anybody help? I am in the dark. The import code goes as follows:
from __future__ import absolute_import, division, print_function
import numpy as np
from stl import mesh
and the error message goes as follows:
Traceback (most recent call last):
File "C:/Users/Riley/PycharmProjects/stExperiments/stCube.py", line 4, in
from stl import mesh
ImportError: cannot import name 'mesh'
Process finished with exit code 1
I had the same problem when installing stl with pip install stl
Try using pip install numpy-stl
It works on my computer (Windows 10)
NOTE:
if you are on python 3.x, simply change pip to pip3
I have a jupyter notebook running on a remote cluster to which I have set up an ssh tunnel. Everything was working fine till today. Now everytime I do :
import matplotlib # This works
%matplotlib inline # This causes kernel to restart
import matplotlib.pyplot # This also causes the kernel to restart
Running a standalone ipython interpreter and doing :
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot ## Leads to Core dumped : Segementation Fault
Running the same on a python interpreter works fine.
Jupyter version : 4.1.1
Python version : 2.7.7
Any help would be much appreciated.
Thank You
Often, this kind of error seems to be related to the backend. Have you tried any other backends? Do these result in the same error? Like this we could narrow down the source of the error.
(I don't have a remote cluster, so I can not reproduce it.)
You can find available backends as described here.
I perhaps have the same problem but on my local machine. I got into jupyter3-qtconsole 4.2.1 with Python 3.4.5 and IPython 5.0.0. and enter
`%matplotlib
Using matplotlib backend: Qt4Agg`
the error message (shortened):
File "/usr/lib64/python3.4/site-packages/tornado/ioloop.py", line 603, in _run_callback
ret = callback()
and finally
from IPython.core.interactiveshell import NoOpContext as context
ImportError: cannot import name 'NoOpContext'
Same thing happens in a notebook but in a straightforward IPython terminal, everything runs OK
Hope this is helpful to someone
This question is related to the already asked question:
Julia error using PyPlot - signal (11): Segmentation fault
However, it is not entirely clear to me what the solution there was, or whether even the steps there apply also to my case (I tried them with no effect).
I have been using Julia 4.6 for some time without any problems.
I then decided to update my Ubuntu distribution from 14 to 16.04.
This is when PyPlot stopped working.
I have updated the Julia Packages, and I also did Pkg.build("PyPlot") to no effect. I also run Pkg.test("PyCall") and it passes all tests succesfuly. I also tried the suggestion
ENV["PYTHON"] = ""; Pkg.build("PyPlot")
The situation right now is the following.
I can import PyPLot normally:
using PyPlot
This gives me no errors.
However, as soon as I invoke any command relating to PyPlot, like:
figure()
I receive the error:
signal (11): Segmentation fault
unknown function (ip: 0x32736)
Segmentation fault (core dumped)
and Julia exits of course.
I don't know if this is relevant, but out of curioustiy I tried the following thing. After starting python in the command line, I do:
import matplotlib.pyplot
which gives me the following error message:
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "/usr/lib/python2.7/dist-packages/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/usr/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 62, in <module>
import matplotlib.textpath as textpath
File "/usr/lib/python2.7/dist-packages/matplotlib/textpath.py", line 15, in <module>
import matplotlib.font_manager as font_manager
File "/usr/lib/python2.7/dist-packages/matplotlib/font_manager.py", line 58, in <module>
from matplotlib import ft2font
ImportError: numpy.core.multiarray failed to import
All help appreciated.
EDIT:
I fixed the problem in python with the import statement by simply uninstalling and reinstalling matplotlib via pip. However, this changed nothing for Julia.
In the end I managed to solve the problem with the help of a colleague.
I first re-installed matplotlib via pip.
I had to point Julia to the system installed Python:
ENV["PYTHON"]="/usr/bin/python"
I then rebuilt PyCall and PyPlot:
Pkg.build("PyCall")
Pkg.build("PyPlot")
Restarted Julia and it worked!
I am using Linux server to set up a django project. I got this error: "Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"
Then I found $MPLCONFIGDIR are empty. So I set it like this:
lab#base:~$ export MPLCONFIGDIR=~/website/graph
lab#base:~$ echo $MPLCONFIGDIR
/home/lab/website/graph
This path is the directory where I want to store images created by Matplotlib.
Then I made sure this setting in python command line:
>>> import matplotlib
>>> import os
>>> os.environ.get('MPLCONFIGDIR')
'/home/lab/website/graph'
BUT, in the django project which is deployed in Apache with mod_wsgi, the above-mentioned error still exits. I added the below lines:
import os
os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
print(os.environ.get('MPLCONFIGDIR'))
It prints "None"!
Can anyone help me?
Thanks.
Set the MPLCONFIGDIR in code before you import matplotlib. Make sure the directory has permissions such that it can be written to by the app.
import os
os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
import matplotlib
Alternatively, you could set it to a tempfile.
import os
import tempfile
os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()
import matplotlib
Per #Esteban I do something like this in modules or scripts:
import os
try:
import matplotlib
except:
import tempfile
import atexit
import shutil
mpldir = tempfile.mkdtemp()
atexit.register(shutil.rmtree, mpldir) # rm directory on succ exit
os.environ['MPLCONFIGDIR'] = mpldir
import matplotlib
This way the temporary directory is removed on exit.