Trouble running a compiled app which includes singleton - python

I'm having trouble running a compiled app which includes singleton, the .pyw compilation proccess goes just fine, but when I attempt to run the resulting .exe, it writes an error log with the message shown below:
Traceback (most recent call last):
File "main.pyw", line 16, in <module>
File "tendo\singleton.pyc", line 20, in __init__
AttributeError: 'module' object has no attribute '__file__'
this is how I'm calling singleton:
from tendo import singleton
me = singleton.SingleInstance()

The tendo's singleton module makes use of sys.modules['__main__'].__file__ to find the main directory. In py2exe it doesn't exist, that's why you get this error.
You can fix it with this answer. In tendo/singleton.py, line 20 you have:
self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' +
os.path.splitext(os.path.abspath(sys.modules['__main__'].__file__))[0] \
.replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')
Replace with something like this:
path_to_script = get_main_dir() #see linkd answer
self.lockfile = os.path.normpath(tempfile.gettempdir() + '/' + path_to_script
.replace("/","-").replace(":","").replace("\\","-") + '-%s' % flavor_id +'.lock')
Report this as an issue to the author, and/or make a pull request with the fix.

Related

"RuntimeError: generator raised StopIteration" every time i run the app. (Nothing Works)

So every time I try to run the app I get "RuntimeError: generator raised StopIteration error". I am using Python 3.7 (btw I don't know how to type fancy in this so its nice to see)
I have tried changing utils.py
yield next(seq) to
try:
yield next(seq)
except StopIteration:
return
but that didn't seem to work. I've also re installed webpy but it didn't work.
import web
urls = (
'/(.*)', 'Hello'
)
app = web.application(urls, globals())
class Hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
This error pops up:
Traceback (most recent call last):
File "C:\Users\Korisnik\Desktop\Python Files\Web\venv\lib\site-packages\web\utils.py", line 526, in take
yield next(seq)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/Korisnik/Desktop/Python Files/Web/main.py", line 6, in
app = web.application(urls, globals())
File "C:\Users\Korisnik\Desktop\Python Files\Web\venv\lib\site-packages\web\application.py", line 62, in init
self.init_mapping(mapping)
File "C:\Users\Korisnik\Desktop\Python Files\Web\venv\lib\site-packages\web\application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "C:\Users\Korisnik\Desktop\Python Files\Web\venv\lib\site-packages\web\utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration
The webpy documentation says that the latest full release (0.39) only works on Python 2. There's work in progress towards supporting Python 3, but for now it's only available in development builds.
You can try installing one of those, with pip install web.py==0.40-dev1.
I was going into my main python folder and changing the yield thing there INSTEAD of going into the folder where my project is. The fix is changing the yield thing to the improved yield thing.

How to commit and push files using python library GitPython

Requirement:
Commit and push files to GitHub repository from a python script.
The credentials should be included in the script.
Issue:
If credentials are provided in the script the commit operation is
executing and throwing the following error,
Traceback (most recent call last):
File "/home/amith/example.py", line 14, in <module>
repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'
If credentials are, not provided in the script the commit operation is working properly by providing it on the terminal.
I need to integrate this script in Django application which should accept the credentials from the configuration file.
I have tried the following links but nothing has worked for me yet.
- link1
- link2
- link3
from git import Repo
from github import Github
from pdb import set_trace as bp
repo_dir = '--------'
repo = Repo(repo_dir)
# using username and password
g = Github("-----", "------")
folder_path = '----------'
commit_message = 'Add New file'
repo.index.add(folder_path)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()
So, I am getting this error "AttributeError: 'Repository' object has no attribute 'index'".
Complete error -
Traceback (most recent call last):
File "/home/amith/example.py", line 14, in <module>
repo.index.add(folder_path)
AttributeError: 'Repository' object has no attribute 'index'

Print Data from PLC to Python using pycomm

I am trying to move data (a dint specifically but my example is a BOOL) from the plc to python to be used as a variable to display a picture. The issue is, if I use pycomm, I am getting an error in Windows Powershell. I feel this is a very simple error from a basic python mistake rather than a pycomm issue but I am not informed enough to tell.
SysInfo:
configparser==3.5.0
cpppo==3.9.7
greenery==2.1
ipaddress==1.0.18
pycomm==1.0.8
pyreadline==2.1
pytz==2017.2
python==2.7.13
Code I am using:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
c = ClxDriver()
if c.open('IPADDRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Which is just a stripped down version of one of the examples on github https://github.com/ruscito/pycomm
This is the result from running powershell:
PS C:\Users\Tom\Documents\PythonProjects> python pycomm2.py
Traceback (most recent call last):
File "pycomm2.py", line 10, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I have looked for this AttributeError and tried to find a solution, but I think the solutions I have found are over my head. If I have failed to provide some details in order for this question to make sense please let me know.
Edit:
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
if __name__ == '__main__':
logging.basicConfig(
filename="ClxDriver.log",
format="%(levelname)-10s %(asctime)s %(message)s",
level=logging.DEBUG
)
c = ClxDriver()
if c.open('IPADRESSHERE'):
print(c.read_tag(['new_Bool']))
c.close()
Yields the same attribute error.
PS C:\Users\Tom\Documents\PythonProjects> python pycommtest.py
Traceback (most recent call last):
File "pycommtest.py", line 15, in
print(c.read_tag(['new_Bool']))
File "C:\Python27\lib\site-packages\pycomm\ab_comm\clx.py", line 359, in read_tag
self.logger.warning(self._status)
AttributeError: 'Driver' object has no attribute 'logger'
PS C:\Users\Tom\Documents\PythonProjects>
I was able to read a value, but not with pycomm. Using CPPPO, I was able to continuously update a variable as needed. This may not answer the question of what was wrong with my old code, but it is my work around in case someone from the future has to do the same thing. Credit to user Liverpool_chris and the abyss of Reddit.
https://www.reddit.com/r/PLC/comments/5x3y5z/python_cpppo_library_writing_to_tag_in_plc/
from cpppo.server.enip.get_attribute import proxy_simple
import time
host = "IPHERE"
while True:
x, = proxy_simple(host).read(( "CPID"))
print x
time.sleep(5)

ConfigParser instance has no attribute '[extension]'

I am learning python and I am trying to do a simple task of reading information from a config file.
So using the Python Doc and this similar problem as a reference I created two files.
This is my config file config.ini (also tried config.cfg)
[DEFAULT]
OutDir = path_to_file/
[AUTH]
TestInt = 100
TestStr = blue
TestParse = blua
and this is my python file test.py
import ConfigParser
from ConfigParser import *
config = ConfigParser()
config.read(config.cfg)
for name in config.options('AUTH'):
print name
out = config.get('DEFAULT', 'OutDir')
print 'Output directory is ' + out
however when running the command python test.py I am erroring out and receiving this error
Traceback (most recent call last):
File "test.py", line 7, in <module>
config.read(config.cfg)
AttributeError: ConfigParser instance has no attribute 'cfg'
Note: I thought that meant it the extension couldn't be read so I created the .ini file and changed it in the code and I received the same error but it instead read ...has no attribute 'ini'
I am not sure what I am doing wrong since I am doing the exact same as the python doc and the solution someone used to fix this similar issue.
config.read takes a string as its argument. You forgot to quote the file name, and config was coincidentally the name of a Python object (the module) that potentially could have a cfg attribute. You'd get an entirely different error if you had written config.read(foobarbaz.ini).
The correct line is
config.read('config.cfg') # or 'config.ini', if that's the file name

libtorrent-python problems, "no such file or directory" when there clearly is

First of all, here's the code
#!/usr/bin/env python3.4
import libtorrent as lt
import os
fs = lt.file_storage()
lt.add_files(fs, "/var/mirror/packages/") # There are two files in this directory
t = lt.create_torrent(fs, flags = 1&8&16) # 1 = Optimization, 8 = Symbolic links, 16 = calculate file hashes.
t.add_tracker("udp://tracker.[private].com:80")
print(os.path.isdir("/var/mirror/packages/"))
lt.set_piece_hashes(t,"/var/mirror/packages/")
print(t.generate())
And here's what happens when I run it
True
Traceback (most recent call last):
File "./test.py", line 9, in <module>
lt.set_piece_hashes(t,"/var/mirror/packages/")
RuntimeError: No such file or directory
This is the page I got this from
I have browsed around the bindings, but I can't find the set_piece_hashes sources. It returns the same error code when I change the path to "." or "/" (keeping the add_files path the same)
Anyone know what I'm doing wrong? I can't find any sort of documentation other than the site I linked above
Turns out set_piece_hashes wants the parent directory of the directory you created the filestore with. After I fixed that, I now get another error, which is a known bug in libtorrent here

Categories