I can import numpy successfully using my python version 2.7.11 on the command line :
but not in IDLE where I get the following error :
Traceback (most recent call last):
File "/Users/macbookpro/Desktop/Python learning/Mortgages/mortgage_plot.py", line 2, in <module>
import pylab
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/matplotlib/__init__.py", line 124, in <module>
from . import cbook
File "/Users/macbookpro/Library/Python/2.7/lib/python/site-packages/matplotlib/cbook/__init__.py", line 35, in <module>
import numpy as np
ImportError: No module named numpy
What could be the source of this problem ?
A possible candidate for this error can be that the numpy package is not present in the directories where your IDLE searches for the package.
However the package is available for your command line python package path. Try adding the package location to your IDLE's package search path. I think that should resolve this error.
You can add following lines at top to add package path ( for this program only ) to use numpy :
import sys
sys.path
sys.path.append('path/to/package/numpy')
import numpy
Download numpy package from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy .
Or you can also work on anaconda
Related
Ive updated my Python version from 3.5.4 to 3.6.6 (in Anaconda 3) and now the line
from sklearn.metrics.pairwise import cosine_similarity
causes the following error:
Traceback (most recent call last):
File "<ipython-input-3-743ac88bcf9a>", line 1, in <module>
from sklearn.metrics.pairwise import cosine_similarity
File "F:\Program Files\lib\site-packages\sklearn\__init__.py", line 64, in <module>
from .base import clone
File "F:\Program Files\lib\site-packages\sklearn\base.py", line 13, in <module>
from .utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\__init__.py", line 13, in <module>
from .validation import (as_float_array,
File "F:\Program Files\lib\site-packages\sklearn\utils\validation.py", line 22, in <module>
from ..utils.fixes import signature
File "F:\Program Files\lib\site-packages\sklearn\utils\fixes.py", line 83, in <module>
from scipy.special import boxcox # noqa
File "F:\Program Files\lib\site-packages\scipy\special\__init__.py", line 640, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
Im on Windows 7, 64-bit; previously the line worked fine, and other packages (Pandas, Numpy etc) still work, so it doesn't appear to be a PATH issue as some have suggested.
Ive seen numerous similar questions but all solutions have so far failed. E.g.
roll the installation back to Python 3.5.4,
uninstall & re-install Pandas, Numpy, Scipy and Sklearn, also update MKL/MKL-RT.
The changes suggested in Error when trying to import sklearn modules : ImportError: DLL load failed: The specified module could not be found
were already implemented
Does anyone have any further suggestions (specific to Anaconda etc)?
I solved it, and (in my case) the problem was scipy, not sklearn.
What i did was uninstall scipy with conda: conda remove --force scipy, and then install it with pip: pip install scipy. That worked for me.
I have installed Numpy 1.13.0 on Windows 10; however, when I try to execute the following code, it gives the above error
#!C:\Users\sukhpreet.singh\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)
import numpy as np
import matplotlib.pyplot as pp
a = np.array([1,2,3,4,5])
print(a.dtype)
Following are the details of error message:
Traceback (most recent call last):
File "numpyy.py", line 4, in <module>
import numpy as np
File "C:\Users\sukhpreet.singh\Project\numpy.py", line 5, in <module>
import matplotlib.pyplot as pp
File "C:\Users\sukhpreet.singh\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "C:\Users\sukhpreet.singh\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\cbook.py", line 33, in <module>
import numpy.ma as ma
ModuleNotFoundError: No module named 'numpy.ma'; 'numpy' is not a package
You also have a module called numpy on python's search path (at C:\Users\sukhpreet.singh\Project\numpy.py).
Unsurprisingly, when matplotlib tries to import numpy.ma it is finding your numpy module, not the library package.
Conclusion: Don't name your modules the same as other packages/libraries you'd like to use.
I wanted to do LDA on some data and so followed this example:
http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html#example-decomposition-plot-pca-vs-lda-py
however, on trying:
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
I got an import error. Huh, maybe this is a new function, I thought. So I updated scikit-learn via conda from 0.15.2 to 0.17. But now I can't even import sklearn:
import sklearn
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "//anaconda/lib/python2.7/site-packages/sklearn/base.py", line 9, in <module>
from scipy import sparse
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/__init__.py", line 213, in <module>
from .csr import *
File "//anaconda/lib/python2.7/site-packages/scipy/sparse/csr.py", line 13, in <module>
from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import
I tried updating numpy and scipy using both pip and conda to no avail. I then tried a complete clean re-install of anaconda by:
rm -rf ~/anaconda
and a subsequent download of the .pkg from http://docs.continuum.io/anaconda/install#anaconda-install
Still I get the same error. Here are my OS and package details:
Mac OSX 10.5.2
bash-3.2$ conda -V
conda 3.18.6
scipy==0.16.0
numpy==1.9.1
scikit-learn==0.17
The last of these via pip freeze since I can't import it. I'm going nuts here. Any help much appreciated.
Try:
conda install numpy=1.10.1
I've had that module compiled against API version a but this version of numpy is 9 error before, and this solved it for me.
Installed Twilio successfully however when I attempt to import it in either the shell or terminal I get this error output:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import twilio
File "/Library/Python/2.7/site-packages/twilio/__init__.py", line 11, in <module>
from .rest.exceptions import TwilioRestException
File "/Library/Python/2.7/site-packages/twilio/rest/__init__.py", line 1, in <module>
from .base import set_twilio_proxy
File "/Library/Python/2.7/site-packages/twilio/rest/base.py", line 6, in <module>
from twilio.rest.resources import Connection
File "/Library/Python/2.7/site-packages/twilio/rest/resources/__init__.py", line 1, in <module>
from .util import (
File "/Library/Python/2.7/site-packages/twilio/rest/resources/util.py", line 5, in <module>
import pytz
ImportError: No module named pytz
Can anyone explain what is happening here? My version of Python is 2.7.9 and my pip installer is current as well. Output Error above is from importing in IDLE shell.
Twilio developer evangelist here.
The Twilio library requires pytz to be installed. Easiest way to get it installed is by running this on your terminal:
pip install pytz
Hope this helps
Good day.
I've been using
pip install simplecv
to install the module simplecv.
I know the module was properly installed and when I'm printing list of the modules using
#!/usr/bin/env python2.7
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
I can see it in the list : 'simplecv==1.3'
But for some reason I can't use it.
I've tried to export the path using
1) export PYTHONPATH="/usr/local/lib/python2.7"
2) export PYTHONPATH="/usr/local/lib/python2.7/site-packages"
3) export PYTHONPATH="/usr/local/lib/python2.7/dist-packages"
But nothing works
Any ideas?
The package name isn't the same as the module name. The module is called SimpleCV, as shown in the documentation. So we have
>>> import simplecv
Traceback (most recent call last):
File "<ipython-input-2-064db77601b3>", line 1, in <module>
import simplecv
ImportError: No module named simplecv
but
>>> import SimpleCV
Traceback (most recent call last):
File "<ipython-input-3-d3da1d75bea1>", line 1, in <module>
import SimpleCV
File "/usr/local/lib/python2.7/dist-packages/SimpleCV/__init__.py", line 3, in <module>
from SimpleCV.base import *
File "/usr/local/lib/python2.7/dist-packages/SimpleCV/base.py", line 59, in <module>
raise ImportError("Cannot load OpenCV library which is required by SimpleCV")
ImportError: Cannot load OpenCV library which is required by SimpleCV
I didn't bother installing the dependencies, so this didn't work, but if I had, it would have. :-)