failed to import numpy as np when I worked with jupyter notebook - jupyter

In Jupyter, there is an ImportError:
import numpy as np
ImportError Traceback (most recent call last)
ipython-input-1-4ee716103900 in module()
----> 1 import numpy as np
ImportError: No mudule named numpy
But in Python, there is no error:
import numpy as np

Usually this happens because your python is one Python environment and whatever you're running your notebook with is another. Try running import sys; sys.executable in both environments and seeing whether or not they match. If they don't, that's your problem: whatever jupyter is running in is borrowing numpy from the root environment.

For ubunutu environment
in jupyter, run:
import sys; sys.executable
This will display the python location eg
/home/paul/notepad_vm/notepad_vm/bin/python
switch to bash shell
cd /home/paul/notepad_vm/notepad_vm/bin/python
./pip install numpy
switch back to Jupyter, run:
import numpy as np

Related

Cannot import torch in jupyterLab

Cannot import torch in jupyterLab.
It shows:
ImportError: cannot import name 'classproperty' from 'torch._utils'
But it works in my Anaconda prompt.
Thanks in advance.

Jupyter Notebook - ModuleNotFoundError when import selfmade module

I can't import any of my selfmade moduls into my jupyter-notebook script.
Pip installed modules like numpy or pandas work.
when calling os.listdir() for my current work directory, the modules are shown.
The current work directory also appears in my sys.path

Python pillow module not importing properly

I'm using the Python pillow module, but every time I try to import it and use a function, it gives me an error. Here is some code to reproduce the error.
import PIL
PIL.ImageGrab.grab()
You have to use from to import from PIL.
from PIL import ImageGrab
ImageGrab.grab()

No module named 'scipy', although installed with Anaconda. Python 3 on Windows 10

I did conda install for numpy, pandas, scipy, and scikit-learn apparently all successful. I also tried to change the path in the Windows 10 registry. I only have 1 version of Python, 3.6 installed. I also installed Visual Studio. If I run the script, I get "scipy module not found". Can you explain me what's the problem, and how to fix this?
My imports look like this:
import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
I'm following this tutorial by Sentdex:
https://www.youtube.com/watch?v=r4mwkS2T9aI&index=4&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v

Enthought Canopy Basemap Import Failure

I'm running Enthought Canopy Version 1.5.2730 with Basemap version 1.0.7-5 and pyproj version 1.9.3-1 installed on a Mac running OS X 10.9.5. When I try to import basemap I get the following error message.
from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-5e6824321d57> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap
/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
28 from matplotlib.lines import Line2D
29 from matplotlib.transforms import Bbox
---> 30 from mpl_toolkits.basemap import pyproj
31 from mpl_toolkits.axes_grid1 import make_axes_locatable
32 from matplotlib.image import imread
ImportError: cannot import name pyproj
If I try to import pyproj directly I get the following error mesage
ImportError Traceback (most recent call last)
<ipython-input-1-0cc08144b629> in <module>()
----> 1 from mpl_toolkits.basemap import pyproj
/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
35 import numpy as np
36 import numpy.ma as ma
---> 37 import _geoslib
38 import functools
39
ImportError: dlopen(/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-package /_geoslib.so, 2): Library not loaded: #rpath/lib/libgeos_c.1.dylib
Referenced from: /Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/_geoslib.so
Reason: image not found
I've tried uninstalling and reinstalling the packages with no success. The missing dylib is on machine in the /opt/local/lib directory. Not sure if it is path problem or something more complicated. Any hints as to how to begin debugging the issue are greatly appreciated.
IIUC, this is due to some libraries that were formerly supplied by basemap, and now are supplied by geos, that were inappropriately removed by updating basemap.
To fix it, open a Canopy Terminal (from the Canopy Tools menu) and type:
enpkg --remove geos
enpkg geos