Cannot import numpy in python3 - python-3.x

I am using python3 in Ubuntu Xenial. I also have version 1.11.0 of python3-numpy package installed
I get errors when attempting to import numpy from python3.
$ python3.6
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
>>>

I simply uninstalled Numpy using:
pip3 uninstall numpy
Then re-installed it:
pip3 install numpy
And somehow this worked.

If you don't mind about what version you are using, you could try pip install numpy==1.7.2 or another older version. This problem has happened to a few people when trying to install the latest versions of numpy.
If you would really like to use it, I would suggest reinstalling numpy. However, using pip uninstall numpy has been known to not work, so manually going into the Python directory, and Lib, and manually deleting the numpy packages would be your best bet.
If this still doesn't work, you may have to completely delete Python and reinstall it all over again.
The following websites may help you: Numpy build fails with cannot import multiarray, Python ImportError "cannot import name 'multiarray'

What you can do is,
Create an environment and then install numpy.
Steps :
virtualenv *your_environment_name*
source *your_environment_name/bin/activate*
sudo pip3 install numpy

Related

Error importing matplotlib on MAC OSX Yosemite

I'm learning to use MAC OS now and have installed python 3.7.9 on it and have run pip commands and installed numpy, matplotlib, jupyter.
Numpy and jupyter work fine but whenever I try to import matplotlib, I get this error.
People on S.O said the installation of the package might be "borked". So i uninstalled and reinstalled it too, but to no avail.
I am unable to make sense of the traceback. Any help is greatly appreciated.
Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> import matplotlib as mpl
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib as mpl
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/__init__.py", line 109, in <module>
from . import _api, _version, cbook, docstring, rcsetup
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/matplotlib/colors.py", line 51, in <module>
from PIL import Image
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/Image.py", line 103, in <module>
from . import _imaging as core
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/_imaging.cpython-37m-darwin.so, 2): Library not loaded: #loader_path/libXdmcp.6.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/.dylibs/libxcb.1.1.0.dylib
Reason: no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/.dylibs/libXdmcp.6.dylib: cannot load 'libXdmcp.6.dylib' (load command 0x80000034 is unknown)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/.dylibs/libXdmcp.6.dylib: cannot load 'libXdmcp.6.dylib' (load command 0x80000034 is unknown)
>>>
I have done
pip3 install --upgrade PILLOW
pip3 install --upgrade python-dateutil (based off of someone's answer on stackoverflow)
I have ununistalled and reinstalled matplotlib using pip
If I run python 2.7(Mac OSX default python installation) in terminal, It imports matplotlib properly. But when I try importing matplotlib in python3, I am getting the above errors.

ImportError: cannot import name parse_date while importing Pandas

Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/suman/.local/lib/python3.6/site-packages/pandas/__init__.py", line 180, in <module>
import pandas.testing
File "/home/suman/.local/lib/python3.6/site-packages/pandas/testing.py", line 5, in <module>
from pandas._testing import (
File "pandas/src/testing.pyx", line 4, in init pandas._testing (pandas/src/testing.c:4068)
File "/home/suman/.local/lib/python3.6/site-packages/pandas/types/missing.py", line 5, in <module>
from pandas import lib
File "pandas/lib.pyx", line 1, in init pandas.lib (pandas/lib.c:87552)
File "pandas/tslib.pyx", line 67, in init pandas.tslib (pandas/tslib.c:109851)
ImportError: cannot import name parse_date
Make sure that you have installed pandas in the proper directiry:
pip install pandas
If you have already done so, it would be worth upgrading pandas:
pip install pandas --upgrade
Hi I got the same error today when I developed a pyqt project. I found there are two "pandas" when I uninstalled one then tried to install again. What I have done was uninstalling both two "pandas", then install the latest version, then it works. Although I solved this on Windows, but hope it is helpful to you.

Pandas module not found, Windows server 2012

All,
I'm running on a Windows 2012 server with Anaconda 2.3.0 64b (2.7) installed and am trying to also have Python 3.6 available. I've installed 3.6 but can't get it to load pandas. I saw another thread that seemed to tie the issue to conda.
I removed and installed pandas again and reset my path to not look at the Anaconda directory but I'm still getting the error.
Any suggestions would be appreciated.
PS C:\Users\yearickp\AppData\Local\Programs\Python\Python36> .\python -m pip list
Package Version
--------------- -------
numpy 1.14.3
pandas 0.23.0
pip 10.0.1
pyodbc 4.0.23
python-dateutil 2.7.3
pytz 2018.4
setuptools 39.1.0
six 1.11.0
SQLAlchemy 1.2.7
PS C:\Users\yearickp\AppData\Local\Programs\Python\Python36> .\python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\__init__.py", line 42, in <mod
ule>
from pandas.core.api import *
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\api.py", line 10, in <mod
ule>
from pandas.core.groupby.groupby import Grouper
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\__init__.py", lin
e 2, in <module>
from pandas.core.groupby.groupby import (
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\groupby\groupby.py", line
49, in <module>
from pandas.core.frame import DataFrame
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 74, in <m
odule>
from pandas.core.series import Series
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py", line 3978, in
<module>
Series._add_series_or_dataframe_operations()
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 8891, i
n _add_series_or_dataframe_operations
from pandas.core import window as rwindow
File "C:\Users\yearickp\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\window.py", line 36, in <
module>
import pandas._libs.window as _window
ImportError: DLL load failed: The specified module could not be found.
>>>
This seems to be an issue with v0.23. Uninstall pandas pip uninstall pandas and install v0.22 instead pip install pandas==0.22 (except you really have to use v0.23).

I've installed python 3 and verified the version of urllib3 is up to date, but every time I try to import urllib3 it says no module named 'urllib3'

Here is the output of pip3 freeze:
Chases-MBP:/ chasehippen$ pip3 freeze
certifi==2018.1.18
chardet==3.0.4
flake8==3.5.0
get==0.0.39
idna==2.6
mccabe==0.6.1
pew==1.1.2
pipenv==9.0.3
post==0.0.26
public==0.0.65
pycodestyle==2.3.1
pyflakes==1.6.0
query-string==0.0.28
request==0.0.26
requests==2.18.4
six==1.11.0
urllib3==1.22
virtualenv==15.1.0
virtualenv-clone==0.2.6
And here's what happens when I try to import requests or urllib3:
Chases-MBP:/ chasehippen$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>> import urllib3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'urllib3'
I reinstalled python 3 via homebrew twice, I don't understand why it won't let me import the modules?
If I run python import urllib2, that works fine, but only urllib3 fails.
Here are the outputs of where
Chases-MBP:~ chasehippen$ which pip3
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3
Chases-MBP:~ chasehippen$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
All of the resources I saw were saying I need to add the paths to .profile or .bashrc, but on mac, or at least mine, it's .bash_profile. I had to add "export PYTHONPATH="${PYTHONPATH}/Library/Frameworks/Python.framewor‌​k/Versions/3.6/bin/"‌​:/usr/local/lib/pyth‌​on3.6/site-packages" to that file, and now importing works like a charm.
For anyone in the future reading this for an answer to using python3 on a mac, the file is ~/bash_profile , adding the line above in place of the default line that python 3 puts in there lets you use all of the modules that are installed in site-packages instead of bin

Keras-ImportError: cannot import name ctc_ops

I have Anaconda 4.3.1 installed in my laptop after the commands cd /home/username/anaconda3and source bin/activate ~/anaconda3 my package starts .
And I installed keras using pip3 conda install keras inside my anaconda. package.and made a document named keras.json inside my keras folder.
When I start my Python in anaconda3 and import keras this happens
>>> import keras'
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tushar/.local/lib/python3.5/site-packages/keras/__init__.py", line 3, in <module>
from . import activations
File "/home/tushar/.local/lib/python3.5/site-packages/keras/activations.py", line 3, in <module>
from . import backend as K
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/__init__.py", line 64, in <module>
from .tensorflow_backend import *
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
from tensorflow.python.ops import ctc_ops as ctc
ImportError: cannot import name 'ctc_ops'
After following this I could not get any solution. I would appreciate any help.
I had this same exact issue (I was using pip instead of conda to install keras / tensorflow, however). Make sure you have the most up-to-date version of tensorflow (tensorflow-1.0.1 as of March 31st, 2017).
sudo pip install tensorflow --upgrade
fixed the problem for me (I was running tensorflow-0.9.0rc0 before and was getting the same ImportError: cannot import name ctc_ops error as you)

Resources