I have some python code which uses function scipy.integrate.simpson
So for example I import scipy using import scipy.integrate as scp_int and then use it in following way:
vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0)
I get this error
vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0)
AttributeError: module 'scipy.integrate' has no attribute 'simpson'`
I have made sure that I have scipy package installed, using pip install scipy, and I have restarted computer. I don't know why is this happening? Can someone give the reason or help me solve this issue?
I suspect you are using version 1.5 (or an older version) of SciPy.
If you don't know which version you have installed, you can check with
import scipy
print(scipy.__version__)
simpson was added in 1.6.0; it is the new name for the old function called simps. If you can't upgrade, you should be able to use simps instead of simpson.
Related
I was trying to run this program below but it's showing the error "No module named 'lab_utils_common'", what can I do to solve this problem?
import numpy as np
import matplotlib.pyplot as plt
from lab_utils_common import plot_data, sigmoid, dcl
plt.style.use('./deeplearning.mplstyle')
lab_utils_common package is either not publicly available or not actively maintained.
Two possible scenarios:
lab_utils_common is a published package, but not installed. Use pip or conda to install.
lab_utils_common is supposed to be a local module written to lab_utils_common.py, but is missing. See more on modules if interested.
I was wondering if you have used the library "trimesh" in python. It looks quite useful, but right now im having some trouble with the method "Trimesh.spli()" on the last line of the code attached. the code was working fine up to that line, which is suppose to return a list of trimesh objects.
However, when I try to run this code, I get the error ImportError: no graph engines available!
Do you know how can I set up a graph engine? or if there is any turnaround this issue?
Thanks for your support,
Regards
import numpy as np
import trimesh
# Load the stl files into the script
mesh = trimesh.load('Path_to_STL_file')
mesh2 = trimesh.load('Path_to_raw_material_in_STL')
# Confirm both files are closed
assert mesh.is_watertight
assert mesh2.is_watertight
#Boolean operation
mesh3 = trimesh.Trimesh.difference(mesh2,mesh)
list_mesh = trimesh.Trimesh.split(mesh3)
I found the issue. The library does not install all dependancies unless you ask for it. Usually, it only requires numpy.
One option to install most of the dependancies is:
pip install trimesh[easy]
or, if that doesn't solve it, you could use:
pip install trimesh[all]
You need to also install either scipy or networkx to satisfy the graph engine dependency. There's a comment in the source code that networkx is 5-10 times slower than scipy so it's probably best to install scipy. If you're using pip then it's
pip install scipy
or if you're using conda:
conda install scipy
I'm new to python and I'm having an issue importing a module that imports numpy,PIL and os packages. I'll try and be as clear as possible with my problem
So I have a module lets call it preprocessing.py in which I've written a class to process an image imported from PIL using Image and converting it to a numpy array so the structure looks like the following (note method1 converts a jpg to numpy array)
----- preprocessing.py
import numpy as np
import os
from PIL import Image
Class process_object:
method1
Now I want to use this module as follows I want to import process_object from preprocessing.py and use method1 to process an image again imported using Image in PIL. So my script computation.py looks like the following
---computation.py
import os
import numpy as np
from PIL import Image
a = process_image(input)
a.method1()
However, when I do this I get the following error message
ImportError: No module named numpy
Could someone explain to me what is going on and how to fix it? I'd really appreciate an explanation which allows me to understand what is going on under the hood, so I can avoid situations like this. I really appreciate any help! Thanks!!
Check in which version of Python pip is installing numpy. It could be that when pip installs it, it's pointing to a different Python version on your system.
For problems like these, I would recommend using:
https://github.com/pyenv/pyenv-virtualenv
Will handle Python versions for you, so that you can differentiate which packages are being installed.
I will also recommend using PyCharm's Community Edition.
https://www.jetbrains.com/pycharm/download
Excellent tool and lets you create your own environment.
Hope this helps.
https://sourceforge.net/projects/numpy/files//NumPy/1.5.0/NOTES.txt/view. This is the support for numpy in Python 3.0. You probably need a newer version of numpy. You can also use:
pip install numpy
or
pip3 install numpy
trying to import scipy.interpolate but it can’t import _fblas.pyd. It keeps throwing the following error
File "C:\cygwin64\lib\python2.7\site-packages\scipy/linalg/blas.py", line 155, in <module>
from scipy.linalg import _fblas
ImportError: cannot import name _fblas
My online research suggested that this is because I had the wrong version of numpy installed, and I need to install numpy+mkl. So I uninstalled the version I had and pip installed numpy 1.10.4, which includes mkl.
This did not fix the original problem with _flbas.pyd.
I would reinstall scipy but I can't remember where I got the version I have, and when I pip install scipy 0.17.1.tar.gz it throws an error saying that it has no blas resources, which are necessary. I've also tried to download it from here: https://github.com/scipy/scipy/releases, but they don't include _fblas.pyd in the first place.
I’m not sure where to go from here. I'm not even entirely sure why it won't import the _fblas.pyd file.
This looks like you tried to manually comply to your needed packages. Even though I take my hat off at your effort, keep in mind that this is not an simple task at all.
I might also add that this kind of work is not meant for a developer ("the person who writes the code"), but a full time maintainer. Specially with your particular Cygwin environment
So, what can you do? Alternatively, you can use one of Continuum's mkl-ready python-and-many-tools-including-mkl+scipy distribution or Enthought's Canopy. Hopefully, this will avoid you lots of hours of staring at the screen wondering what's wrong
I have imported scipy by this command in pycharm:
import scipy as sp
but as I want to use it in this way for example:
a=sp.special.factorial(5)
I receive an error related to module attribute and I have to import scipy in below way only, to get no error:
from scipy import special
but in another IDE like Spyder both commands runs with no error.
I use anaconda as interpretor in pycharm.
I am not familiar with Spyder. Perhaps they did something extra. But the official way of doing is you have to import scipy.special serapately.
import scipy
help(scipy) # it will give the following help message.
Help on package scipy:
NAME
scipy
DESCRIPTION
SciPy: A scientific computing package for Python
================================================
Documentation is available in the docstrings and
online at http://docs.scipy.org.
Contents
--------
SciPy imports all the functions from the NumPy namespace, and in
addition provides:
Subpackages
-----------
Using any of these subpackages requires an explicit import. For example,
``import scipy.cluster``.