scipy does not load correctly in pycharm - python

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

Related

"No module named 'lab_utils_common'"

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.

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

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()

python packages -- overriding built-in packages and the dreaded "Module xxxx was already imported" warning

I'm creating a self-contained python tool, located in a directory, which I want some colleagues of mine to be able to run with a standard python distribution that includes numpy and matplotlib. I don't want them to have to install additional libraries.
─myprogram
| __main__.py
| [...other .py files...]
├───datafiles
├───sandbox
└───xlrd
├───doc
└───examples
I am using the xlrd library, which I included in my program distribution so that they don't have to install it.
I've tested my program to make sure it works with Enthought EPD, PortablePython, and PythonXY.
Here's the problem: PythonXY can be installed with the xlrd library. When I went to run my program with PythonXY, I got this warning:
c:\app\python\pythonxy-2.7.5.0\lib\site-packages\scikits\__init__.py:1:
UserWarning: Module xlrd was already imported from myprogram\xlrd\__init__.pyc,
but c:\app\python\pythonxy-2.7.5.0\lib\site-packages is being added to sys.path
__import__('pkg_resources').declare_namespace(__name__)
How can I tweak my source code so that it imports only the embedded xlrd library that I provide, and not the installed one, if one is installed?
Clarification:
Aside from the printed warning, is there any side effect that can happen? I want the embedded version of xlrd to be used, not the global copy installed within python.
If there's nothing wrong, how can I suppress this warning for this library only?
Rename myprogram\xlrd to myprogram\frozen_xlrd.
Then import it with
try:
import xlrd
except ImportError:
import frozen_xlrd as xlrd
Alternatively, you could tell Python to silently ignore this particular UserWarning:
import warnings
warnings.filterwarnings("ignore",
message="Module xlrd was already imported",
category=UserWarning)
Place this early on in the program, before scikits gets imported.

Categories