I want to run nvidia-detect and capture the output in a list or even a string that I can do a string comparison of the output to what I require.
I need to know if the system requires kmod-nvidia or kmod-nvidia-340xx.
I have searched and came up with two possible ways of capturing the output of nvidia-detect.
My initial code was:
test=str(os.system('nvidia-detect'))
print test
my output is:
kmod-nvida
256
where 256 is the value of test.
So after searching I tried:
test2=subprocess.check_output('nvidia-detect', shell=True)
and get this error:
Traceback (most recent call last):
File "/home/emmdom/PycharmProjects/mycode/nvidia_update.py", line 8, in <module>
test2=subprocess.check_output('nvidia-detect')
AttributeError: 'module' object has no attribute 'check_output'
I got it work this is what ended up working for me. Thanks
import os
os.system('yum -y yum-plugin-nvidia nvidia-detect')
nvidia='kmod-nvidia'
nvidia_340='kmod-nvidia-340xx'
chk_nvidia=(os.popen('nvidia-detect').read()).rstrip()
print chk_nvidia
if chk_nvidia == nvidia:
print 'nvidia'
os.system('yum -y kmod-nvidia')
if chk_nvidia == nvidia_340:
print 'nvidia-340-xxx'
os.system('yum -y kmod-nvidia-340xx')
Related
I'm new to Python and I want to run the Duplex tool (https://github.com/beurtschipper/Depix ). But the test version does not start, when I type an in the command line:
python depix.py -p images/testimages/testimage3_pixels.png -s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png -o output.png
an error occurs:
Traceback (most recent call last):
File "F:\Work\Projects\Python\Depix\Depix-main\depixlib\depix.py ", line 10, in <module>
from. import __version__
Error Importer error: an attempt at relative import without a known parent package
In the READMI written
sh
depix \
-p /path/to/your/input/image.png \
-s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png \
-o /path/to/your/output.png
But I do not know how to run it, please help
I had the same error and it looks like it is a directory structure problem.
You can fix it by adding depixlib where you import the modules.
depixlib\depix.py
from depixlib import __version__
from depixlib.functions import
from depixlib.LoadedImage import LoadedImage
from depixlib.Rectangle import Rectangle
Hope it fixed your problem!
Now, I get the following errors, but that's another story. 😅
LoadedImage.py
return cast(list[list[tuple[int, int, int]]], _imageData)
TypeError: 'type' object is not subscriptable
edit: Actually I fixed the above by changing the following line to:
Last line of LoadedImage.py file
return cast(list(list([int, int, int])), _imageData)
It was mentionned here: https://github.com/beurtschipper/Depix/pull/83
Cheers!
I used indentation method in the code but it throws a error. Need solution please. My python version is Python 2.7.15+
Code:
import textwrap
s = 'hello\n\n \nworld'
s1 = textwrap.indent(text=s, prefix=' ')
print (s1)
print ("\n")
s2 = textwrap.indent(text=s, prefix='+ ', predicate=lambda line: True)
print (s2)
Code is taken from geeksforgeeks
Output Error:
python Textwrap5.py
Traceback (most recent call last):
File "Textwrap5.py", line 4, in <module>
s1 = textwrap.indent(text=s, prefix=' ')
AttributeError: 'module' object has no attribute 'indent'
It might be that your file is located in a directory called textwrap or you have other file called textwrap in the same or parent directory.
Try changing the directory name or the file and see if it works
Python2.7, textwrap doesn't have indent function available.
Either use initial_indent or subsequent_indent as per your requirement OR upgrade to Python3.x
This is my code:
with open (basefile,"r") as file:
for servers in file.read().splitlines():
rsltfile = servers+"_SNMPCHECK_RSLT.txt"
command = (["snmp-check","-c"],["community.txt"],servers,[">>"],rsltfile)
with open(rsltfile,"w") as rslt:
subprocess.call(command)
And this is the Traceback for it:
Traceback (most recent call last):
AttributeError: 'list' object has no attribute 'rfind'
I couldn't paste every line in the Traceback because it kept giving me errors. But anyway I can't seem to use the call method and I get this error and I don't know what is happening.
Don't use a nested list/tuple.
>> is a shell feature, which in my tests doesn't seem to work, even with shell = True. It might work if your command was a string instead of a list, but that's not ideal either.
command = ["snmp-check","-c","community.txt",servers]
with open(rsltfile,"a") as rslt: # note the "a"
subprocess.call(command, stdout=rslt)
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)
I am working on a Raspberry Pi 3 and I am trying to visualize some values of sensors on Munin. I am using Python in order to execute scripts on Munin.
I found a script to test and I am trying to execute it but I got the following error :
Traceback (most recent call last):
File "cpu_field", line 23, in
munin.main()
AttributeError: 'module' object has no attribute
'main'
This is the script : https://github.com/CooledCoffee/python-munin/
Of course, I added at the beginning :
!/usr/bin/env python
But, what I didn't understand is that others scripts are working like this one :
https://gist.github.com/tomoconnor/813813
Would be nice if you could put the code in the question as well.
Anyways. The python-munin you use is entirely different and provides no main() function (as it called in line 23). Names for python modules are not protected and
'munin' is a obvious choice used by more than one developer.
The first script should run with the module you get with
pip install python-munin
The other script uses this python-munin module and you probably get it directly from the git repository. They are not compatible.
So, this is the code I am using :
> #!/usr/bin/env python
>
> import munin
>
> category = 'system' fields = [
> 'load1',
> 'load5',
> 'load15', ] vlabel = 'load'
>
> def values():
> with open('/proc/loadavg') as f:
> data = f.read()
> load1, load5, load15 = [float(s) for s in data.split()[:3]]
> return {
> 'load1': load1,
> 'load5': load5,
> 'load15': load15,
> }
>
> if __name__ == '__main__':
> munin.main()
This is the answer I got with sudo python xxx, I got the same answer with sudo munin-run xxx :
pi#dex:/etc/munin/plugins $ sudo python first
Traceback (most recent call last):
File "first", line 24, in <module>
munin.main()
AttributeError: 'module' object has no attribute 'main'
I thin you are right because when I installed munin with
pip install python-munin
it worked. But, then I installed this python-munin module and it didn't work anymore. I removed the folder python-munin but I still got the same error.
How can I remove properly the previous folder ?