ModuleNotFoundError: No module named 'numpy.testing.nosetester' - python

I was using the Decision Tree and this error was raised. The same situation appeared when I used Back Propagation. How can I solve it?
import pandas as pd
import numpy as np
a = np.test()
f = open('E:/lgdata.csv')
data = pd.read_csv(f,index_col = 'id')
x = data.iloc[:,10:12].as_matrix().astype(int)
y = data.iloc[:,9].as_matrix().astype(int)
from sklearn.tree import DecisionTreeClassifier as DTC
dtc = DTC(criterion='entropy')
dtc.fit(x,y)
x=pd.DataFrame(x)
from sklearn.tree import export_graphviz
with open('tree.dot','w') as f1:
f1 = export_graphviz(dtc, feature_names = x.columns, out_file = f1)
Traceback (most recent call last):
  File "<ipython-input-40-4359c06ae1f0>", line 1, in <module>
    runfile('C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib/_numpy_compat.py', wdir='C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib')
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "C:/ProgramData/Anaconda3/lib/site-packages/scipy/_lib/_numpy_compat.py", line 9, in <module>
    from numpy.testing.nosetester import import_nose
ModuleNotFoundError: No module named 'numpy.testing.nosetester'

This is happening due to a version incompatibility between numpy and scipy. numpy in its latest versions have deprecated numpy.testing.nosetester.
Replicating the issue
pip install numpy==1.18 # > 1.18
pip install scipy<=0.19.0 # <= 0.19
and
from sklearn.tree import DecisionTreeClassifier as DTC
Triggers the error.
Fixing the error
Upgrade your scipy to a higher version.
pip install numpy==1.18
pip install scipy==1.1.0
pip install scikit-learn==0.21.3
But not limited to this. By upgrading the above libraries to the latest stable, you should be able to get rid of this error.

I needed to upgrade scipy
pip3 install -U scipy

I was facing the same error while using lexnlp package
Got it fixed by installing:
scipy==1.4.1
pandas==0.23.4
numpy==1.18.1
lexnlp==0.2.7.1
(Only install lexnlp if know you're explicitly using it in your project and you know what you're doing)

I solved this by:
pip uninstall numpy
pip install numpy == 1.17.0
and using:
from numpy.testing import rundocs

I also faced same issue while loading the model and fixed by upgrading below libraries
pip install -U numpy
pip install -U pandas
pip install -U scipy

try installing numpy version 1.17.0 using pip or pip3
(assuming you already installed pip3)
pip3 install numpy==1.17.0

If you are using Jetson TX2 or any other aarch64 based device. You can solve the issue by installing latest numpy and scipy libraries.
This also works for x86 based systems. (You can skip libatlas-base-dev and gfortran for x86 based systems)
sudo pip3 install numpy==1.19.0
sudo apt-get install libatlas-base-dev gfortran
sudo pip3 install scipy==1.5.1

For me it solved by this link, apparently an open issue.
Downgrade to numpy==1.16.4

Related

pip install geopandas on windows

I am relatively new to python and trying to install geopandas on python 3.7 using pip. For separate reasons, I would like to avoid using the anaconda distribution. Following this post, I was able to successfully install geopandas by first installing the dependencies manually. The problem is that now I run into a problem when I try to import geopandas:
import geopandas
The subsequent error message is:
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\geopandas\__init__.py", line 5, in <module>
from geopandas.io.file import read_file
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\geopandas\io\file.py", line 4, in <module>
import fiona
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fiona\__init__.py", line 87, in <module>
from fiona.collection import BytesCollection, Collection
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fiona\collection.py", line 9, in <module>
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: DLL load failed: The specified module could not be found.
Any advice would be greatly appreciated
My case is similar to yours. And here is how I got mine setup:
Platform: Windows 10, 64-bit Python Version: Python 3.7
Dependencies (whl files needed):
GDAL‑3.0.4‑cp37‑cp37m‑win_amd64.whl
Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl
pyproj‑2.6.0‑cp37‑cp37m‑win_amd64.whl
Rtree‑0.9.4‑cp37‑cp37m‑win_amd64.whl
Steps:
Download the files that match the platform and Python version from
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Install packages (stick with the order)
a) C:\Users...\Python37\Scripts>pip3.7 install C:...\GDAL‑3.0.4‑cp37‑cp37m‑win_amd64.whl
b) C:\Users...\Python37\Scripts>pip3.7 install C:...\Fiona‑1.8.13‑cp37‑cp37m‑win_amd64.whl
c) C:\Users...\Python37\Scripts>pip3.7 install C:...\pyproj‑2.6.0‑cp37‑cp37m‑win_amd64.whl
d) C:\Users...\Python37\Scripts>pip3.7 install C:...\Rtree‑0.9.4‑cp37‑cp37m‑win_amd64.whl
Given no errros, now it's good to go:
C:\Users...\Python37\Scripts>pip3.7.exe install geopandas
Test it using IDEL 3.7.4
import geopandas as pdg
(It works!)
This works for me and I hope this is also helpful for you.
I had trouble installing geopandas on (win-64, Spyder3.8, Python3.8.3)
Use this expression to install geopandas in anaconda prompt:
conda install -c conda-forge/label/cf202003 geos
(do not use this website: https://geopandas.org/install.html)
(do not use this expression: conda install --channel conda-forge geopandas)
The simplest method to install geopandas is:
conda install geopandas
In order to update geopandas to latest version use the following command after installation by conda:
pip install geopandas --upgrade
There are other installation methods also explained in Geopandas official website.
Conda is really powerful when it comes to installation as it will install the dependencies needed by the package. However, if you would like to install dependencies earlier than use the following command:
conda install pandas fiona shapely pyproj rtree descartes
Note that if you have installed the dependencies using above command then you can also use pip to install geopandas but before installing via pip dependencies are required to be installed. In order to read more about dependencies, please follow the official guide. To install using pip use the following command:
pip install geopandas

Problem with CV2 : numpy.core.multiarray failed to import

Tried to solve it with :
pip install -U numpy
but it still does not work.
That is what the console shows to me when I try to run the application :
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "/Users/Rubio/Desktop/logistic-regression/train.py", line 8, in <module>
import cv2
File "/Library/Python/2.7/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
Uninstall & Install Numpy
conda uninstall numpy
conda install -c conda-forge numpy
it works
I had a file named numbers.py in the same folder.
Removing this file solved the issue for me.
Very strange, but worked.
Two solutions. I faced this problem with ai2thor environment.
Just add import numpy.core.multiarray before the import cv2 statement
Update number: pip install -U --no-cache-dir numpy==1.19.3
Reinstall OpenCV:
conda install -c anaconda opencv (for anaconda users)
I discovered that my problem was that I had two versions of numpy installed, I uninstall one of them and it worked normal.
I faced this error with Tello Drone "DJITelloPy" and this solution from Soroush Karimi saved the day.
pip uninstall numpy
pip install numpy==1.19.3

Pandas not properly installed in venv

On ubuntu 16.4.4 with Python 2.7.12, I was trying to install pandas and some other packages with pip in virtualenv. The installation proceeded without any errors. However, when I try to import pandas, I get the following error:
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa
Traceback (most recent call last):
...
import pandas as pd
File "/usr/local/lib/python2.7/dist-packages/pandas/__init__.py", line 31, in <module>
"extensions first.".format(module))
ImportError: C extension: umpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
My system has pandas of the same version(0.18.0) and runs without any problem.
What I tried and did not work:
create a new virtualenv with the --system-site-packages option.
reinstall pandas (in venv)
upgrade pandas (in venv)
upgrade numpy (from 1.11.0 to 1.14.3) (in venv)
uninstall numpy and pandas and install pandas again (in venv)
This looks like a similar problem to this one https://github.com/pandas-dev/pandas/issues/18530 i.e. mismatch between some specific versions of numpy and pandas. The pip install numpy --upgrade didn't work for me but
python -m pip install pandas==0.18.0 --force-reinstall --upgrade --no-deps --no-cache
did the trick in my case (I encountered this problem on fresh Ubuntu 17.10, python2).
Update numpy version:
pip install numpy --upgrade
Should fix the error.

Python Sklearn.Model_Selection giving error unable to import comb

I am importing train_test_split as:
from sklearn.model_selection import train_test_split and it is giving an error cannot import name 'comb'.
The versions I am using are scipy 0.18.1 and sklearn 0.17.1
Below is the detail of error, please guide here if you feel something is wrong.
Traceback (most recent call last):
File "<ipython-input-21-e45e815fd516>", line 1, in <module>
from sklearn import model_selection
File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\__init__.py", line 1, in <module>
from ._split import BaseCrossValidator
File "C:\Users\rahulsharma53\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 31, in <module>
from ..utils.fixes import signature, comb
ImportError: cannot import name 'comb
The suggestion in the comment above worked for me.
scikit-learn version 0.17.1 doesn't have the 'model-selection' module (it has instead the 'cross_validation' module, reference here). Since you have Anaconda installed, trying to upgrade scikit-learn to the newest version using the pip installer may cause a mismatch with the installed scipy and numpy versions (upgrading them with the pip installer wont solve the problem). The solution is to upgrade all three libraries using anaconda's installer, but before that all existing versions must be uninstalled, first using pip (in case, like me, you already went the pip route) then using conda.
Following the suggestions in the referred link:
pip uninstall:
pip uninstall numpy scipy -y
pip uninstall scikit-learn -y
conda uninstall:
conda uninstall numpy scipy scikit-learn -y
conda install:
conda install numpy scipy scikit-learn -y
Don't forget to restart Anaconda before retrying your import clause.

SciPy package on Fedora 20: ImportError: cannot import name anderson_ksamp

I'm trying to run a Python package called D3E for single-cell differential gene expression. I have Python 2.7.5 on Fedora 20. I just installed the SciPy package using the instructions here:
sudo yum install numpy scipy python-matplotlib ipython python-pandas sympy python-nose
However, when I try to run the script, I keep getting a SciPy error:
bash-4.2$ python D3ECmd.py ~/Documents/geneExpressionTable.txt ~/outputFile.txt cellType1 cellTYpe2 -n=0, -z=1
Traceback (most recent call last):
File "D3ECmd.py", line 34, in <module>
from D3EUtil import readData, getParamsBayesian, getParamsMoments, cramerVonMises, logStatus, goodnessOfFit, distributionTest
File "/home/user/Software/D3E/D3EUtil.py", line 36, in <module>
from scipy.stats import gmean, ks_2samp, anderson_ksamp
ImportError: cannot import name anderson_ksamp
What would you recommend I try to fix this error?
Thanks.
As #Warren pointed out, anderson_ksamp is not available in scipy version .12.1. It is a relatively new addition to scipy.
I'm not a fedora user. That said, it sounds like installing scipy using pip is your best bet.
Step one: install dependencies. Check Muneeb's answer for information on how to install blas and lapack on fedora. It should be as simple as:
sudo yum install lapack lapack-devel blas blas-devel
Step two: install scipy using pip.
sudo pip install --upgrade scipy
This process will take a long time. Get lunch. You should have a working copy of scipy when you get back.
Note, if you don't have pip, run the following command:
sudo yum install python-pip

Categories