scipy.stats attribute not found - python-3.x

I tried to import scipy.stats as ss but it keeps showing me an import error:
Traceback (most recent call last):
File "E:\My Python Files\KNN_Classification.py", line 4, in <module>
import scipy.stats
File "D:\Python3.6\lib\site-packages\scipy\stats\__init__.py", line 343, in <module>
from .stats import *
File "D:\Python3.6\lib\site-packages\scipy\stats\stats.py", line 169, in <module>
import scipy.special as special
File "D:\Python3.6\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.
What should I do?

Most likely a wrong installation. You should remove the build directory as well as the installed scipy in site-packages, and then reinstall scipy.

Related

ModuleNotFoundError: No module named 'scipy.sparse.base'

I'm trying to run from sklearn import preprocessing, but it raise an error:
Traceback (most recent call last):
File "<ipython-input-6-d27a4e3c0526>", line 1, in <module>
from sklearn import preprocessing
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/__init__.py", line 82, in <module>
from .base import clone
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/base.py", line 17, in <module>
from .utils import _IS_32BIT
File "/Users/x/anaconda3/lib/python3.6/site-packages/sklearn/utils/__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "/Users/x/.local/lib/python3.6/site-packages/scipy/sparse/__init__.py", line 227, in <module>
from .base import *
ModuleNotFoundError: No module named 'scipy.sparse.base'
How could I deal with it?
The version of scipy is 1.5.4.
Using pip3 install --upgrade --user scipy solved the problem for me.

Why does a DLL error appear when importing tensorflow?

I recently got a new 64-bit windows 10 and installed pycharm. The pycharm I am using is Python 3.8.
When I installed tensorflow by running the command line, it worked fine. However, when I imported on my pycharm file (i.e. import tensorflow as tf), it produced an error as such:
Traceback (most recent call last):
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/leode/PycharmProjects/Science Fair/project.py", line 1, in <module>
import tensorflow as tf
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\leode\anaconda3\envs\Science Fair\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Failed to load the native TensorFlow runtime.
However when I import tensorboard_plugin_wit:
import tensorboard_plugin_wit
It works fine.
What went wrong? If any of you need any further clarification, please comment- I'm not much of an expert on handling computers so I will do my best to answer:)
I figured out what the problem was. Unlike many third-party modules in python, installing tensorflow requires more than simply pip install . The way I installed tensorflow was by creating and activating a conda environment. For more information on how to install tensorflow via Pycharm, here is a helpful Youtube video: https://www.youtube.com/watch?v=5Ym-dOS9ssA&t=327s

Matplotlib and numpy import don't work after pycharm 2019 optimize imports

I used Pycharm 2019.1's import optimization on a full project and now the imports for matplotlib and numpy don't work.
Here is the full error code:
Traceback (most recent call last):
File "C:/Users/LENOVO/PycharmProjects/CSinternal/LearnIt.py", line 8, in <module>
import matplotlib
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\matplotlib\__init__.py", line 139, in <module>
from . import cbook, rcsetup
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\matplotlib\cbook\__init__.py", line 31, in <module>
import numpy as np
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\__init__.py", line 141, in <module>
from . import core
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\__init__.py", line 37, in <module>
from . import multiarray
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\multiarray.py", line 20, in <module>
from . import overrides
File "C:\Users\LENOVO\PycharmProjects\CSinternal\venv\lib\site-packages\numpy\core\overrides.py", line 45, in <module>
""")
RuntimeError: implement_array_function method already has a docstring
I'm new here and honestly don't know what this ( RuntimeError: implement_array_function method already has a docstring) means.
Any help is much appreciated.
I had the same issue and the solution for me appeared when I realized that I had imported torch as two different names in different files in the same project. By renaming them I got rid of the error. I suspect you might have a similar issue. Try running the code in a new project without any other files in the same project.

ImportError: Importing the multiarray numpy extension module failed

I am trying to write Python script in Java using ScriptEngine. But when I import tflearn module it gives me following errors.
javax.script.ScriptException: ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in <script> at line number 1
at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:222)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:59)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at com.ultimatix.bot.JavaRunCommand.main(JavaRunCommand.java:48)
Caused by: Traceback (most recent call last):
File "<script>", line 1, in <module>
File "D:\Python\Lib\site-packages\tflearn\__init__.py", line 4, in <module>
from . import config
File "D:\Python\Lib\site-packages\tflearn\config.py", line 3, in <module>
import tensorflow as tf
File "D:\Python\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "D:\Python\Lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
import numpy as np
File "D:\Python\Lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "D:\Python\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "D:\Python\Lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "D:\Python\Lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "D:\Python\Lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
I also tried to import some different package like sys, pickle. They are getting imported successfully.
Python version: 3.5.4
OS: Window 7 - 64 bits
Numpy is written in Fortran and compiled to binary. For that reason, it is not compatible to be ran on the JVM. The other packages you are importing are implemented in pure python.
CPython, the standard python implementation, has done a lot of work to stay compatible at the binary level. Numpy arrays have the same memory layout as C arrays, which do not have the same memory layout as Java arrays. As you go deeper into python there are a lot more incompatibilities as to why it won't work.

error of import scipy.stats for windows 7

I use windows 7 and installed python 3.5 32bit. I installed numpy 1.11 + mkl win32 whl version for python 3.5 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
and installed scipy 0.17.0 from the same site same way. I use pip install. No problem import numpy and scipy, but see error when import scipy.stats or from scipy import stats, etc... Here is the error message:
if from scipy import stats:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from scipy import stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 627, in <module>
from ._ufuncs import *
File "scipy\special\_ufuncs.pyx", line 1, in init scipy.special._ufuncs (scipy\special\_ufuncs.c:26242)
ImportError: DLL load failed: The specified module could not be found.
If use import scipy.stats see below error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import scipy.stats
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\stats\stats.py", line 180, in <module>
import scipy.special as special
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\Programs\Python\Python35-32\lib\site-packages\scipy\special\basic.py", line 14, in <module>
from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta,
ImportError: cannot import name 'ellipkm1'
I have searched for solution from websites but could not find an answer. Please help. This is really frustrating...
Thanks
Rocky
Ok, finally I solved this myself. At the beginning I knew I needed the 2015 visual C++ redistribution and had it installed, the problem is I installed the 64bit one while obviously I should have used 32 bit one since my python and numpy, scipy were all 32 bit.
Hope this helps for other people

Resources