Strange import scipy in Eclipse with Pydev, no auto completion [duplicate] - python

I have an issue with importing the scipy.special package. It isn't harmful, just annoying/interesting.
When I import scipy using import scipy as sp and then try to access sp.special I get:
>>> import scipy as sp
>>> sp.special
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'special'
>>>
but if I then do import scipy.special I can access the special module through scipy.special and sp.special:
>>> import scipy as sp
>>> import scipy.special
>>> scipy.special
<module 'scipy.special' from 'C:\Python27\lib\site-packages\scipy\special\__init__.pyc'>
>>> sp.special
<module 'scipy.special' from 'C:\Python27\lib\site-packages\scipy\special\__init__.pyc'>
>>>
So I now have the special module accessible through both sp and scipy namespaces. The interesting bit is that I can access the rest of scipy through the scipy namespace.
First question: Why does the special module not import first time round?
Second question: How can I get access to the special module through the sp namespace only, without defining the scipy namespace?
Edit: using Python 2.7.2 and scipy 0.10.1

By default, "import scipy" does not import any subpackage. There are too many subpackages with large Fortran extension modules that are slow to load. I do not recommend doing import scipy or the abbreviated import scipy as sp. It's just not very useful. Use from scipy import special, from scipy import linalg, etc.

Related

Why can't I use scipy.linalg after importing scipy?

If I run the following two lines of code:
import numpy
numpy.linalg
I do not get an error, and I get the output <module 'numpy.linalg' from /Users/...>.
However, if I run the following two lines of code
import scipy
scipy.linalg
I get the error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-7ed633b28ccc> in <module>
1 import scipy
----> 2 scipy.linalg
AttributeError: module 'scipy' has no attribute 'linalg'
However, the following code seems to work fine:
import scipy.linalg
scipy.linalg
My question is: how come after importing numpy, I can use numpy.linalg, but I can't do the same for scipy?
For context, I am using numpy version 1.19.2, and I am using scipy version 1.4.1.
There is a line in "numpy/__init__.py", which is the module initialization file, that explicitly imports linalg:
from . import linalg
There is no such line in "scipy/__init__.py". That is why you must import scipy.linalg yourself.

module in repo not found in local version of python package

I would like to use the physics.quantum.TensorProduct' method insympy`. Looking at the repo this method definitely exists. However when attempting to import into my python session I get the following:
>>> from sympy import *
>>> physics.quantum.TensorProduct(v1,v2)
Traceback (most recent call last):
File "<pyshell#271>", line 1, in <module>
physics.quantum.TensorProduct(v1,v2)
AttributeError: module 'sympy.physics' has no attribute 'quantum'
I installed sympy seamlessly using pip as pip install sympy. If I try to upgrade pip install sympy --upgrade I get the Requirement already up-to-date message.
Why is this that this script is not included? How can I get it so that it is downloaded from the repo and recognized in my python session?
Thanks
It seems that the physics package is not imported in sympy.__init__.__all__ so you cannot access it in your local scope with a simple from sympy import *
>>> from sympy import *
>>> 'physics' in dir()
False
Instead you could import the class you want manually. For example :
>>> import sympy.physics.quantum.tensorproduct
>>> sympy.physics.quantum.tensorproduct.TensorProduct
<class 'sympy.physics.quantum.tensorproduct.TensorProduct'>

ImportError: No module named vis (Python )?

Hello l tried to run my python code and the errors is:
Traceback (most recent call last):
File "/home/anelmad/Desktop/simulation/Theano-Tutorials-master/3_net.py", line 5, in <module>
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
ImportError: No module named vis**
knowing that l have correctly installed foxhound.
import theano
from theano import tensor as T
import numpy as np
from load import mnist
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
from scipy.misc import imsave
is Foxhound a scikit? if yes, it doe's not contains utils module. You can clone it on github https://github.com/IndicoDataSolutions/Foxhound
I have met with the same problem. from foxhound vis import grayscale_grid_vis is enough. And I just comment out the other part. And the program works well. It seems that the module is not used.

ConvexHull and scipy throws an error when importing in qgis

When I am trying to import ConvexHull from scipy I am getting an error.
from scipy.spatial import ConvexHull
**Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name ConvexHull**
Here what I am doing wrong?
I am using scipy0.12.0 version.But when I am importing scipy and scipy.spatial I am not getting any error.
I think this is what you are looking for
from scipy import spatial
spatial.qhull?
Type: module
Base Class: <type 'module'>
String Form:<module 'scipy.spatial.qhull' from '/usr/lib/python2.7/dist-packages/scipy/spatial/qhull.so'>
Namespace: Interactive
File: /usr/lib/python2.7/dist-packages/scipy/spatial/qhull.so
Docstring:
Wrappers for Qhull triangulation, plus some additional N-D geometry utilities
.. versionadded:: 0.9
But it is true, you should be able to import the ConvexHull directly from version 0.12.0 on.
New in version 0.12.0.
I'm using 0.9 so that is why I have to use the Qhull library.

Import does work in console but not script

I try to run Sympy, a library for Python but I got a problem...
When I import Sympy in the console
>>> import os
>>> from os import chdir
>>> chdir("C:/sympy-0.7.2")
>>> import sympy
>>>
It works, but if I make a script with this content...ERROR!
Why ?
This error
Traceback (most recent call last):
File "**", line 4, in <module>
import sympy
ImportError: No module named sympy
try this..
import sys
sys.path.append("C:/sympy-0.7.2")
import sympy
Run the script from C:/sympy-0.7.2.
Better yet, install sympy. It will go into your site-packages directory
and will be available from anywhere. Going into C:/sympy-0.7.2 and typing python setup.py install should work.

Categories