I am trying to use the arch module in python. After installing it, I succesfully imported arch_model by executing from arch import arch_model.
However, I also need to use other functions, such as ConstantMean, as documented on the maintainers github here.
Yet, when I try to import it, it gives me the following error:
ImportError: cannot import name 'ConstantMean' from 'arch'
(C:\Users\frede\anaconda3\envs\earnings_risk\lib\site-packages\arch_init_.py)
When I check the functions available in the module via dir(arch) it also does not list ConstantMean, nor most of the other functions that should theoretically be available according to the documentation. What can be the reason for this? Any help is appreciated.
Try This:
from arch.univariate import ConstantMean
Related
I was trying to some code in python and noted this peculiar case.
import importlib
print(importlib.abc)
The above code runs fine in python 3.7 but not in python 3.10.2. In python 3.10.2, i get the following error:
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean: '_abc'?
I tried to look at the documentation as to whether the behaviour of the above code got changed somehow. But couldn't find it. The documentations i tried looking are Python 3.7 importlib documentation and Python 3.10.2 importlib documentation.
So i wish to know how to find things imported by an import statement on a python standard library through documentation.
Note: I do know that i can look at dir(importlib) to see everything importlib has after it is imported. But i want to find it through documentation so i can know them without using that specific python version.
If you want to import a submodule of a package, you should do so explicitly:
import importlib.abc
Python will not automatically load all submodules of a package when you import the package. Whether submodules will be available without an explicit submodule import depends on whether some code somewhere else in the program has already loaded the module.
As for the question in the title, documentation will usually not have the information you're asking for. Good documentation will thoroughly describe a module's entire public API, but you're asking for information beyond that.
You could use python dir() function to know what importlib contains
import importlib
dir(importlib)
Or a slightly different method is hasattr(importlib,'abc') which returns a boolean.
Yet again another way is via the inspect module
import importlib
import inspect
inspect.getmembers(importlib) #Show all methods,attribute and ...
inspect.getmembers(importlib, inspect.ismodule) #Show only modules
I am running Python 3 and have skbio v0.5.5 installed. Following the examples in this tutorial, I am trying to run the import statements for some skbio classes, but am getting errors. For example,
from skbio.alignment import Alignment
results in
ImportError: cannot import name 'Alignment' from 'skbio.alignment'
Also,
from skbio import BiologicalSequence
results in
ImportError: cannot import name 'Alignment' from 'BiologicalSequence'
How do I resolve this?
The Alignment class is from an older version of the skbio library, specifically from before version 0.3.
If you would like to use those classes, you would need to install scikit-bio from before that version, by doing something like:
pip install scikit-bio==0.2
If you're just going through the Introduction to Applied Bioinformatics book, like you mentioned in your comment, it's better to use the latest version of the book instead, which will use the latest version of the scikit-bio library.
I can't get this simple statement to work:
from plyer import notification
getting:
ImportError: cannot import name 'notification'
the import statement is correct and is used the same way in examples.
I couldn't find any special instructions to use this library so I'm assuming there aren't any.
I installed plyer using pip and it installed successfully. verified the files are in place. I tried using python 3.5 and 3.6, same result.
It seems the package is recognized but just the module isnt found?
Would appreciate some insight :)
A common cause for this kind of problem is having a script or module by the same name in a location that comes before the expected module or package's location in sys.path so it gets imported instead of the expected module or package.
The simple way to sort this out is to add this simple line before:
import plyer; print(plyer);
and check the result which will diplay the path of whatever named plyer was first found. Chances are it's a script in your current working directory...
On my system I have two versions of Python (to call them I type python and python2 in the command line). When I use the first version of Python, I cannot import sklearn module but I can do it in the second version of Python.
I would like to use the first version of python (because other modules are available there) and, at the same time, I would like to be able to import sklearn from this version of Python.
My solution was to use:
import sys
sys.path.append('location_of_the_sklearn_module')
To find the location of the sklearn module I started a python session (using the second version of python, in which sklearn works). The I type:
import sklearn
sklearn.__file__
As a result I got:
/home/name/my_name/numpy/local/lib/python2.7/site-packages/sklearn/__init__.pyc
In the session of the first version of Python I tried:
import sys
sys.path.append('/home/name/my_name/numpy/local/lib/python2.7/site-packages/sklearn')
import sklearn
Unfortunately it did not work. As a result I got: ImportError: No module named sklearn
Does anybody know what I am doing wrong and if it is possible to reach the goal in the way I try?
When importing packages, you need to add the parent directory of the package to PYTHONPATH, not the package directory itself, so just change...
sys.path.append('/home/name/my_name/numpy/local/lib/python2.7/site-packages/sklearn')
...to...
sys.path.append('/home/name/my_name/numpy/local/lib/python2.7/site-packages')
...although it may not necessarily import correctly in Python 3.x.
I am trying to get an example application running with blackberry-py. I adhered to the instructions at link: http://hg.microcode.ca/blackberry-py/wiki/Home , however when trying the
"import bbpy" statement I received the following error: import Error: No module named Qtcore.
Print screen of Trace : http://imgur.com/csRJ4
Any help would be much appreciated.
Thanks
Your version of PySide does not have a module QtCore. Also note that it's trying to import Qt from there, not qt so it makes sense that import qt will give an error.
Are you sure you installed compatible versions of PySide and bbpy? Check the versions and lookup if they're indeed compatible.
It turns out those packages are not for PC but for playbook. Solution is to download PyQt or QT
Thanks to #peter9477 and timeless for the help on #bbx-python on freenode.net.
If you're interested in the BBPy project check it out here : http://blackberry-py.microcode.ca/ and here: http://hg.microcode.ca/blackberry-py/wiki/Home .