"No module named 'lab_utils_common'" - python

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.

Related

Why scipy.integrate shows has no "simpson" attribute?

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.

python module that imports another python module

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

scipy does not load correctly in pycharm

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``.

Python: Why isn't this submodule being loaded?

I installed scikit-learn with pip (pip install -U scikit-learn). I then went to ipython and ran import sklearn, but if I then try to load any modules, they aren't found. In particular, the tab completion of sklearn doesn't seem correct:
In [2]: sklearn.
sklearn.base sklearn.clone sklearn.externals sklearn.re sklearn.setup_module sklearn.sys sklearn.test sklearn.warnings
Any idea what's going on here? Other modules load fine. For example, numpy works normally.
Import the submodule you want to use explicitly:
import sklearn.<submodule>
print sklearn.<submodule>.function()
or
from sklearn.<submodule> import function
print function()
In large python packages, oftentimes the submodules need to be explicitly imported. This is so that the user can pick and choose what to import without importing the entire package (which can negatively affect startup time).

Can't find module in python

I'm trying to do a linear regression using scipy.stats.linregress(). However when I run my script, i get the error message
AttributeError: 'module' object has no attribute 'stats'*
I'm using the Anaconda python 2.7 distribution which in its documentation says to have the module installed. Anaconda documentation
In the python interactive interpreter, I can import the scipy module, but can't find stats. When I look up its __version__ it says 0.14, which should have the stats module..
I really can't guess why the stats is unavailable..
This error:
AttributeError: 'module' object has no attribute 'stats'
Means what it says. There is no attribute named stats in the scipy module.
Not because no such thing exists on disk, but because no such thing has been imported—because you never even tried to import it.
scipy is a package. As the Python tutorial explains, importing a package doesn't import all of its submodules.
Some packages have a __init.py__ that automatically imports some or all packages.* But that would be a bad idea for scipy, because there are a ton of them, so it would take some time to import all of them, and usually you only need one or two in a given project.
So, you just need to do this:
import scipy.stats
* There are also some cases like os which fake being packages but aren't, so you can use os.path without importing it, or cases like pyobjc that create special placeholder objects for their modules that automatically import the real modules when first accessed.
I get the same error when I import scipy instead of scipy.stats. Have you tried
import scipy.stats
scipy.stats.linregress()

Categories