I'm annotating types for the aiojira library using stub files. aiojira library follows the same structure as jira library. jira library contains resilientsession module, so I think I should create resilientsession.pyi file and import it in __init__.pyi. I did this, but when write:
import aiojira.resilientsession
PyCharm complains, mypy complains:
kgjirawebhook/__init__.py:7: error: Cannot find module named 'aiojira.resilientsession'
How do I fix this?
This might be because aiojira is not installed in your current environment. Relative import should fix this problem.
Try:
from . import resilientsession
Related
I'm using a Python library (pyPyrTools), which is giving me an import error.
../../../venv/lib/python3.8/site-packages/pyPyrTools/__init__.py:1: in <module>
from binomialFilter import binomialFilter
E ModuleNotFoundError: No module named 'binomialFilter'
Inspecting the module in venv/lib/site-packages, I find the following structure:
-pyPyrTools
---__init__.py
---binomialFilter.py
And inspecting __init__.py, it's a pretty standard fare import:
from binomialFilter import binomialFilter
binomialFilter.py does include a function called binomialFilter.
Any idea why I'm getting this error from this library? There aren't any relative imports or anything funky, and the files all exist on the right level. It all looks correct to me.
The module looks like it was written for 2.7, and I'm using 3.8 if that is relevant.
I am having trouble getting an import statement to work. I am attempting to use this package:
https://github.com/mailgun/talon
I am running the following command:
from talon.signature import EXTRACTOR_FILENAME, EXTRACTOR_DATA
I get the following error:
ImportError: cannot import name 'EXTRACTOR_FILENAME' from 'talon.signature' (system path to file)
While troubleshooting I don't see EXTRACTOR_FILENAME or EXTRACTOR_DATA defined anywhere. I did a search in directory for all files. Is there some sort of convention in python where EXTRACTOR_FILENAME maps to a specific class?
UPDATE: Figured it out, just something as simple as manually defining the 2 constants. The docs weren't exactly clear or I missed it.
For your project the import looks like this:
import talon
from talon import quotations
Put those statements on the top of your file, and it should work.
if you don't have the packages on your system type this in your terminal:
pip install talon
The Github repo also explains this
My goal is to create a python script that loops over cells of an excel document. This is my python script called reader.py, and it works just fine.
import xlrd
import os
exceldoc = raw_input("Enter the path to the doc [C:\\folder\\file.xlsx]: ")
wb = xlrd.open_workbook(exceldoc,'rb')
.... some code....
The problem I'm encountering is attempting to use py2exe to create an executable so this script can be used elsewhere.
Here is my setup.py file:
from distutils.core import setup
import py2exe
import sys
from glob import glob
setup(name='Excel Document Checker',console=['reader.py'])
I run the following command: python setup.py py2exe
It appears to run fine; it creates the dist folder that has my reader.exe file, but near the end of the command I get the following:
The following modules appear to be missing
['cElementTree', 'elementtree.ElementTree']
I did some searching online, and tried the recommendations here Re: Error: Element Tree not found, this changing my setup.py file:
from distutils.core import setup
import py2exe
import sys
from glob import glob
options={
"py2exe":{"unbuffered": True,"optimize": 2,
'includes':['xml.etree.ElementPath', 'xml.etree.ElementTree', 'xml.etree.cElementTree'],
"packages": ["elementtree", "xml"]}}
setup(name='Excel Document Checker',options = options,console=['reader.py'])
I'm now getting an error:
ImportError: No module named elementtree
I'm sort of at an impasse here. Any help or guidance is greatly appreciate.
Just some information - I'm running Python 2.6 on a 32 bit system.
You explicitly told setup.py to depend on a package named elementtree here:
"packages": ["elementtree", "xml"]}}
There is no such package in the stdlib. There's xml.etree, but obviously that's the same name.
The example you found is apparently designed for someone who has installed the third-party package elementtree, which is necessary if you need features added after Python 2.6's version of xml.etree, or if you need to work with Python 1.5-2.4, but not if you just want to use Python 2.6's version. (And anyway, if you do need the third-party package… then you have to install it or it won't work, obviously.)
So, just don't do that, and that error will go away.
Also, if your code—or the code you import (e.g., xlrd) is using xml.etree.cElementTree, then, as the py2exe FAQ says, you must also import xml.etree.ElementTree before using it to get it working. (And you also may need to specify it manually as a dependency.)
You presumably don't want to change all the third-party modules you're using… but I believe that making sure to import xml.etree.ElementTree before importing any of those third-party modules works fine.
I'm working on a plugin architecture and need to convert a package name like "foo.bar" to the absolute path where the code resides. imp.find_module seems to do what I want, except when the code in question is installed via an egg-link (installed via 'pip install develop').
If there are two modules foo.bar and foo.bar2 which are installed via egg-links (and which live at completely separate file system locations like /home/bob/foo/bar and /home/alice/foo/bar2), find_modules doesn't work because I look up the package "foo" and get the location to foo/bar, but not foo/bar2.
Anyone have suggestions for an alternative function? find_modules doesn't accept hierarchical names, so I can't just pass "foo.bar2" into it.
The easiest way would be to just import the module and inspect its __file__ attribute:
import os
import foo.bar
print(os.path.abspath(foo.bar.__file__))
For dynamic imports:
import os
import sys
module_name = 'foo.bar'
__import__(module_name)
print(os.path.abspath(sys.modules[module_name].__file__))
how can i import other external libraries in web2py? is it possible to
load up libs in the static file?
can somebody give me an example?
thanks
peter
If the library is shipped with python, then you can just use import as you would do in regular python script. You can place your import statements into your models, controllers and views, as well as your own python modules (stored in modules folder). For example, I often use traceback module to log stack traces in my controllers:
import traceback
def myaction():
try:
...
except Exception as exc:
logging.error(traceback.format_exc())
return dict(error=str(exc))
If the library is not shipped with python (for example, pyodbc), then you will have to install that library (using distutils or easy_install or pip) so that python can find it and run web2py from the source code: python web2py.py. Then you will be able to use regular import statement as described above. Before you do this make sure you installed the library properly: run python interpreter and type "import library_name". If you don't get any errors you are good to go.
If you have a third party python module or package, you can place it to modules folder and import it as shown below:
mymodule = local_import('module_name')
You can also force web2py to reload the module every time local_import is executed by setting reload option:
mymodule = local_import('module_name', reload=True)
See http://web2py.com/book/default/section/4/18?search=site-packages for more information.
In web2py you import external library as you normally do in Python
import module_name
or
from module_name import object_name
I am not sure what you mean by "in the static file"