pyforms cannot import conf from pysettings - python

This is my python file:
import pyforms
import pyside
from pyforms import BaseWidget
from pyforms.Controls import ControlText
from pyforms.Controls import ControlButton
class SimpleExample1(BaseWidget):
def __init__(self):
super(SimpleExample1,self).__init__('Simple example 1')
#Definition of the forms fields
self._firstname = ControlText('First name', 'Default value')
self._middlename = ControlText('Middle name')
self._lastname = ControlText('Lastname name')
self._fullname = ControlText('Full name')
self._button = ControlButton('Press this button')
#Define the button action
self._button.value = self.__buttonAction
def __buttonAction(self):
"""Button action event"""
self._fullname.value = self._firstname.value +" "+ self._middlename.value + \
" "+ self._lastname.value
#Execute the application
if __name__ == "__main__":
pyforms.startApp( SimpleExample1 )
And I got an error in the __init__.py file:
Traceback (most recent call last):
File "C:\Python27\Ashish\pyforms\1.py", line 1, in <module>
import pyforms
File "C:\Python27\lib\site-packages\pyforms\__init__.py", line 4, in <module>
from pysettings import conf;
ImportError: No module named pysettings
Here is my __init__.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
from pysettings import conf;
conf += 'pyforms.gui.settings'
__author__ = "Ricardo Ribeiro"
__credits__ = ["Ricardo Ribeiro"]
__license__ = "MIT"
__version__ = '0.1.7.3'
__maintainer__ = "Ricardo Ribeiro"
__email__ = "ricardojvr#gmail.com"
__status__ = "Production"
logger = logging.getLogger(__name__)
if conf.PYFORMS_MODE in ['GUI', 'GUI-OPENCSP']:
from pyforms.gui import Controls
from pyforms.gui.BaseWidget import BaseWidget
if conf.PYFORMS_MODE in ['GUI-OPENCSP']:
from pyforms.gui.appmanager import startApp
else:
from pyforms.gui.standaloneManager import startApp
elif conf.PYFORMS_MODE in ['TERMINAL']:
from pyforms.terminal import Controls
from pyforms.terminal.BaseWidget import BaseWidget
from pyforms.terminal.appmanager import startApp
elif conf.PYFORMS_MODE in ['WEB']:
from pyforms_web.web import Controls
from pyforms_web.web.BaseWidget import BaseWidget
from pyforms_web.web.appmanager import startApp

You will need to download and install pysettings from https://github.com/UmSenhorQualquer/pysettings/tree/92bde8c680bc0a00ae97cc09bd4dab1b697d6ed2

Related

ModuleNotFoundError: No module named 'A given module in package' when running the code

Here is the entire code:
MyApp/
* mypkg/
* __init__.py
* mod1.py
* mod2.py
* Demo.py
I am trying to run this app from Demo.py
mod1.py :
class Person:
def __init__(self,name,age,address):
self.name = name
self.age = age
self.address = address
def show_person(self):
return "the name of the person is {0} and age is {1} ".format(self.name,self.age)
mod2.py :
import mod1 as P
class Student(P.Person):
def __init__(self,name,age,address,standard,grade):
super(Student,self).__init__(name,age,address)
self.standard = standard
self.grade = grade
def show_student(self):
return "The name of the student is {0} and he is studing in {1} standard".format(self.name,self.standard)
__init__.py:
__all__ = ["mod1","mod2"]
Demo.py :
from mypkg import *
a = Person('John',12,'Near S School')
print(a.show_person())
b = Student('name', 17, 'Near X Resturant',12, 'B')
print(b.show_student())
The output:
Traceback (most recent call last):
File "d:\ROOT\WORK\Python\MyApp\Demo.py", line 1, in <module>
from mypkg import *
File "d:\ROOT\WORK\Python\MyApp\mypkg\mod2.py", line 1, in <module>
import mod1 as P
ModuleNotFoundError: No module named 'mod1'
The output should be a string with name and standard
Example :
The name of the Student is Jhon and he is studying in standard 10.
In mod2.py, change the import to
import mypkg.mod1 as P
In Demo.py, change the import to
from mypkg.mod1 import Person
from mypkg.mod2 import Student
This should allow you to run the program.

Why can't I run the example code of the Python package corpcrawl?

I installed corpcrawl but when I try to run this code from its documentation page:
from corpcrawl.crawler import CorpCrawl
from corpcrawl.backend import Backend
def main()
I get the following error
from corpcrawl.crawler import CorpCrawl
Traceback (most recent call last):
File "<ipython-input-40-a34fa6bf09cd>", line 1, in <module>
from corpcrawl.crawler import CorpCrawl
File "C:\ProgramData\Anaconda3\lib\site-packages\corpcrawl\crawler.py", line 1, in <module>
from parser import Parser
ImportError: cannot import name 'Parser'
def main()
File "<ipython-input-44-eaaf015e0d6b>", line 1
def main()
^
SyntaxError: invalid syntax
Why am I getting this error?
The code from corpcrawl's documentation page is broken:
Missing :
Wrong indentation
Illegal characters (such as “ instead of ")
Here is what it should look like (Python 2):
from corpcrawl.crawler import CorpCrawl
from corpcrawl.backend import Backend
class MyBackend(Backend):
def get_company(self, name):
pass
def add_company(self, comp):
print "Adding %s" % str(comp)
def main():
my_backend = MyBackend()
crawler = CorpCrawl(cache_path = '/an/absolute/path/to/some/dir', backend = my_backend)
c.crawl(years = [2011, 2012], quarters = [1, 2, 3, 4])

AttributeError: 'ExampleApp' object has no attribute 'browse_folder'

from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import ADJ_Search
import os
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import webbrowser
class ExampleApp(QtGui.QMainWindow, ADJ_Search.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.Chose_File_Button.clicked.connect(self.browse_folder)
self.List_Search_Button.clicked.connect(self.search_list)
def browse_folder(self):
self.List_ADJ_View.clear()
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.AnyFile)
directory = QStringList()
if dlg.exec_():
directory = dlg.selectedFiles()
f = open(directory[0], 'r')
with f:
data = f.readlines()
for ADJ in data:
self.List_ADJ_View.addItem(ADJ.strip())
print ADJ.strip()
def search_list(self):
self.List_ADJ_View.clear()
print ''
def main():
app = QtGui.QApplication(sys.argv)
form = ExampleApp()
form.show()
app.exec_()
if __name__=='__main__':
main()
Error:
Error:Traceback (most recent call last):
File "temperary.py", line 45, in <module>
File "temperary.py", line 40, in main
form = ExampleApp()
File "temperary.py", line 15, in __init__
self.Chose_File_Button.clicked.connect(self.browse_folder)
AttributeError: 'ExampleApp' object has no attribute 'browse_folder'
Please help me to see why it always come out this error, also 'search_list' has this kind of error too. What do you think is causing it?

Django import settings error

I have the following script for scraping a webform:
#!/usr/bin/env python
"""
Python script for searching firms on http://www.adviserinfo.sec.gov/IAPD/Content/Search/iapd_Search.aspx
Assumes that the input Excel file is in the same directory as this script.
"""
import os
import re
import sys
import django
import mechanize
from bs4 import BeautifulSoup
from xlrd import open_workbook
XLSX_FILE = 'Legal Names.xlsx'
IAPD_URL = 'http://www.adviserinfo.sec.gov/IAPD/Content/Search/iapd_Search.aspx'
#------------------------------------------------------------------------------------------
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), 'scraper/')))
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), 'scraper/scraper/')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
django.setup()
from django.core.exceptions import ObjectDoesNotExist
from custom_scraper.models import *
#------------------------------------------------------------------------------------------
def legal_names(file=XLSX_FILE):
'''
Read in legal names from the excel spreadsheet with the assumption
that names to be searched for are in column 1. Skip row 1 header
'''
wb = open_workbook(file)
s = wb.sheets()[0]
col = 1
for row in range(s.nrows)[1:]:
name = s.cell(row, col).value
if type(name) == int:
continue
yield name
class IapdScraper(object):
def __init__(self):
self.br = mechanize.Browser()
self.br.addheaders = [('User-agent',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7')]
def scrape(self, q):
'''
Search for a Firm in the IAPD database by name
'''
def select_form(form):
return form.attrs.get('id', None) == 'aspnetForm'
try:
firm = IapdFirm.objects.get(query_name=q)
except ObjectDoesNotExist:
firm = IapdFirm(query_name=q)
firm.save()
else:
if firm.checked:
return
self.br.open(IAPD_URL)
self.br.select_form(predicate=select_form)
self.br.form['ctl00$cphMainContent$ucUnifiedSearch$rdoSearchBy'] = ['rdoOrg']
self.br.submit()
self.br.select_form(predicate=select_form)
self.br.form['ctl00$cphMainContent$ucUnifiedSearch$txtFirm'] = q.encode('utf8')
self.br.submit()
s = BeautifulSoup(self.br.response().read())
r = re.compile(r'^ctl\d+_cphMainContent_grOrgResults$')
t = s.find('table', id=r)
if not t: # Not found
print 'Not Found'
firm.checked = True
firm.save()
return
tr = t.findAll('tr', recursive=False)
tr = tr[2:-1] # Skip records-per-page header/footer and title header
for row in tr:
td = row.findAll('td', recursive=False)
firm.legal_name = td[0].b.text.strip()
firm.other_name = td[1].text.strip()
firm.sec_number = td[2].text.strip()
firm.address = td[3].text.strip()
firm.checked = True
firm.save()
if __name__ == '__main__':
scraper = IapdScraper()
for name in legal_names():
print '\nq=%s' % name
scraper.scrape(q=name)
When I run the script in my venv, however, I get the following error:
c:\Users\bal2155\venv\Scripts>scraper.py
Traceback (most recent call last):
File "C:\Users\bal2155\venv\Scripts\scraper.py", line 26, in <module>
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __ge
tattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set
up
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 98, in __in
it__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'settings' (Is it on sys.path? Is there a
n import error in the settings file?): No module named settings
I have a inkling that this has to do either with how I've set up the venv or how I downloaded django. I've checked the documentation for the latter and I'm not sure what the myproject.settings extension means. Any help here would be greatly appreciated.

buildbot doesn't accept my MailNotifier's IEMailLookup object

A number of people in my organization have different email names from perforce names, so I need to create an IEmailLookup derivation that overrides getAddress to do my evil bidding:
(From my master.cfg)
class MyIEmailLookup:
from buildbot import interfaces
__implements__ = interfaces.IEmailLookup
def getAddresses(user):
address_dict = {"user1", "user_one#our_domain.com"}
try:
address = address_dict[user]
except KeyError:
address = user + "#our_domain.com"
return address
maillookup = MyIEmailLookup()
from buildbot.status import mail
c['status'].append(mail.MailNotifier(....
....
lookup=maillookup
))
I've tried any number of permutations, but I either get:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/buildbot-0.8.3p1-py2.6.egg/buildbot/scripts/runner.py", line 1071, in doCheckConfig
ConfigLoader(configFileName=configFileName)
File "/Library/Python/2.6/site-packages/buildbot-0.8.3p1-py2.6.egg/buildbot/scripts/checkconfig.py", line 46, in __init__
self.loadConfig(configFile, check_synchronously_only=True)
File "/Library/Python/2.6/site-packages/buildbot-0.8.3p1-py2.6.egg/buildbot/master.py", line 727, in loadConfig
exec f in localDict
File "/Users/playbuilder/buildbot/master.cfg", line 207, in <module>
lookup=maillookup
File "/Library/Python/2.6/site-packages/buildbot-0.8.3p1-py2.6.egg/buildbot/status/mail.py", line 293, in __init__
assert interfaces.IEmailLookup.providedBy(lookup)
AssertionError
...or any other number of issues, dependant upon how I try to implement the IEmailLookup interface.
I'm using buildbot 0.8.3p1 and python 2.6.1.
I see precious few examples of how to do this, and every one of them fails in my context. What am I missing here?
I just solved this problem myself.
First you need to add (somewhere at the top of the file)
from zope.interface import implements
and then change
__implements__ = interfaces.IEmailLookup
to
if implements:
implements( interfaces.IEmailLookup )
else:
__implements__ = interfaces.IEmailLookup
If you want to fetch email from perforce user, you can use this class:
# .-----------------------.
# | Perforce Email Lookup |
# `-----------------------'
from twisted.internet import defer, utils
from buildbot.util import ComparableMixin
from buildbot.interfaces import IEmailLookup
from zope.interface import implements
import os
import re
class PerforceEmailLookup(ComparableMixin):
implements(IEmailLookup)
compare_attrs = ["p4port", "p4user", "p4passwd", "p4bin"]
env_vars = ["P4CLIENT", "P4PORT", "P4PASSWD", "P4USER",
"P4CHARSET"]
def __init__(self,
p4port = None,
p4user = None,
p4passwd = None,
p4bin = 'p4'):
self.p4port = p4port
self.p4user = p4user
self.p4passwd = p4passwd
self.p4bin = p4bin
self.email_re = re.compile(r"Email:\s+(?P<email>\S+#\S+)\s*$")
def _get_process_output(self, args):
env = dict([(e, os.environ.get(e)) for e in self.env_vars if os.environ.get(e)])
d = utils.getProcessOutput(self.p4bin, args, env)
return d
#defer.deferredGenerator
def getAddress(self, name):
if '#' in name:
yield name
return
args = []
if self.p4port:
args.extend(['-p', self.p4port])
if self.p4user:
args.extend(['-u', self.p4user])
if self.p4passwd:
args.extend(['-P', self.p4passwd])
args.extend(['user', '-o', name])
wfd = defer.waitForDeferred(self._get_process_output(args))
yield wfd
result = wfd.getResult()
for line in result.split('\n'):
line = line.strip()
if not line: continue
m = self.email_re.match(line)
if m:
yield m.group('email')
return
yield name
usage would look like:
c['status'].append(
MailNotifier(
sendToInterestedUsers = True,
mode = 'failing',
lookup = PerforceEmailLookup(
p4port = "perforce:1666",
p4user = "buildbot",
p4passwd = "buildbot")))
Try this:
from buildbot.interfaces import IEmailLookup
from buildbot.util import ComparableMixin
from zope.interface import implements
class lookup_example_email(ComparableMixin):
implements(IEmailLookup)
def getAddress(self,user):
return "%s#example.com"%(user)
...
mn = MailNotifier(..., lookup=lookup_example_email(), extraRecipients=m)
Here's the piece of code I use which works with buildbot 2.3.1 in python3.6.
from buildbot.interfaces import IEmailLookup
from buildbot.util import ComparableMixin
from zope.interface import implementer
#implementer(IEmailLookup)
class EmailMap(ComparableMixin):
def getAddress(self, name):
return f'{name}#xxxxx'

Categories

Resources