I have a problem when trying to run a code for a course at the university. The main file BASEchange.py tries to import 2 modules called "NODE" and "MESHMODEL". "MESHMODEL", in turn, imports RegularGridInterpolator from scipy.interpolate .
When I run the program in the mac terminal, using "python BASEchange.py -h", I get the following error:
ImportError: cannot import name RegularGridInterpolator
I have scipy intalled via pip.
Here are the first lines form meshModel.py:
import sys, os, platform, subprocess, stat, re, abc, math, linecache, shutil
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from scipy import interpolate
from scipy.sparse import csc_matrix, lil_matrix, tril, find
from scipy.sparse.csgraph import reverse_cuthill_mckee
Thanks in advance!
You probably have the wrong version of scipy. Note that RegularGridInterpolator are only supported from version 0.14.
Do the following.
upgrade your pip
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
Then Follow the commands from here to install scipy:
python -m pip install --user scipy
Related
Hi everyone, I'm trying to create a network visualization with python using the networkx package. Unfortunately I'm getting a "AttributeError: module 'scipy.sparse' has no attribute 'coo_array'" at the end of my code. I've tried to fix it but every help in the internet points towards upgrading pip or conda which I've done and still get the same error. I'm using jupyter notebooks - any help would be greatly appreciated!
#Prerequisites
import sys
!{sys.executable} -m pip install --user networkx
!{sys.executable} -m pip install --user numpy
!{sys.executable} -m pip install --user pandas
pip install notebook --upgrade
conda upgrade notebook
import networkx as nx
import numpy as np
import pandas as pd
from pathlib import Path
from pandas import DataFrame
#Read in Source File - NB this must match the schema requirements
df_InputData = pd.read_excel("/Users/paulkruse/Desktop/FR/Fr1.xlsx")
Src_Column = 'Source ID'
Tgt_Column = 'Target ID'
print(df_InputData);
#Nodes are positioned using the Fruchterman-Reingold force-directed algorithm.
Q = nx.Graph()
arr_SrcTgt= np.array(df_InputData[[Src_Column, Tgt_Column]])
print(arr_SrcTgt);
Q.add_edges_from(arr_SrcTgt)
dict_Coords = nx.spring_layout(Q)
It seems that your scipy version is out of date. The most recent version 1.8.1 certainly has coo_array function. One way to resolve this should be to upgrade scipy. If you're doing this from inside jupyter notebook, then use
!pip install --user scipy==1.8.1
Make sure to restart kernel after installation.
I am trying to run survival analysis in python (pycharm) in linux, here is a part of the code
import numpy as np
import matplotlib.pyplot as plt
#matplotlib inline
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import train_test_split
from sksurv.datasets import load_flchain
from sksurv.linear_model import CoxPHSurvivalAnalysis
I get the error "ModuleNotFoundError: No module named 'sksurv'", I tried everything, but nothing works.
The required dependencies for scikit-survival,
cvxpy
cvxopt
joblib
numexpr
numpy 1.12 or later
osqp
pandas 0.21 or later
scikit-learn 0.22
scipy 1.0 or later
...will be automatically installed by pip when you run:
pip install scikit-survival
However, one module in particular, osqp, has CMake as one of its dependencies. If you don't have CMake installed, pip install scikit-survival will throw an error and the installation will fail.
You can download CMake for your OS at cmake.org/download
After CMake has installed, you should be able to successfully run
pip install scikit-survival
Notes:
GCC needs to be installed also
scikit-survival works with Python 3.5 or higher
More information is available in the docs
from sklearn import svm
ImportError: cannot import name __check_build
I've been able to install scikit-learn on a fresh virtualenv here but it seems you need to do some extra job to get it up-and-running:
By doing just pip install scikit-learn and then from sklearn import svm you'll get import errors, it seems the library requires numpy and scipy. So you need to do:
pip install numpy scipy
After that it should work fine.
I'm working in Ubuntu as Virtual-Box guest on top of Windows machine (as host), and I am attempting to run my python script from the terminal. I had difficulty installing matplotlib using pip install. I managed to install it using
sudo apt-get install python-matplotlib
However, I am unable to bring up an image I have created in my code:
import numpy as np
import matplotlib.pyplot as plt
import random as random
from random import randrange
image = plt.imshow(mymatrix)
plt.show()
If I import matplotlib as:
import matplotlib as plt
I am recieving the following error on attempting to run the script:
AttributeError: 'module' object has no attribute 'imshow'
If I import matplotlib as:
import matplotlib.pyplot as plt
I recieve the following error:
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk
package
On attempting to install python-tk using 'pip install python-tk' this is what I'm getting:
~/ising $ pip install python-tk Collecting python-tk Could not find
a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
I'm unsure if I have in fact incorrectly installed matplotlib from the beginning. I am aware pyplot is not automatically imported with matplotlib, could the same be true for installing it from the console? Seems like I have tried everything at this stage.
The problem appears to be that you do not have a graphical backend installed. The error you are getting about Python Tk is happening because normally Tk comes with any Python distribution, so you should have at least that. You can install any Python bindings for Tk, Pyqt4, Pyqt5, Wx, GTK, (possibly others) to get a working interactive graphical backend. Check the package repository for the actual package names to install.
Keep in mind that functions like imshow are part of the (sub)package matplotlib.pyplot, not matplotlib itself. import matplotlib as plt is simply wrong if you intend to do plt.imshow(...). The correct import is either from matplotlib import pyplot as plt or import matplotlib.pyplot as plt.
According to the documentation here try this
python -mpip install -U pip
python -mpip install -U matplotlib
I am trying to import odeint in python by doing:
from scipy.integrate import odeint
but there is an error note:
ImportError: No module named scipy.integrate
I have looked through some websites and there is a module called scipy.integrate, I am not sure what is going wrong with my code?
I also tried
from scipy import arange
which also shows similar error message:
ImportError: No module named scipy
I am using Python 2.7.8. Is it due to the version of Python? How can I fix it then?
If I could not even import them, I won't be able to continue writing my code.
Could somebody please give some advice?
Thanks.
This happens when scipy is not installed.
Download & Install SciPy from : Scientific Python
Ubuntu & Debian : sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Fedora: sudo yum install numpy scipy python-matplotlib ipython python-pandas sympy python-nose
Windows : Unofficial Windows Binaries for Python Extension Packages
SciPy source