maya python subprocess error - python-2.7

in python 2.7 i try this code to get data from Deadline software. Its return some data from server...
import subprocess
path = 'C:/Program Files/Thinkbox/Deadline7/bin/'
p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE)
p1.communicate()
and see result:
('none\r\npool_01\r\npool_02\r\npool_03\r\npool_04\r\npool_05\r\npoolhalf\r\n', None)
but when i copy that code to python in maya 2014 i get error:
p1 = subprocess.Popen(['path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE)
# Error: WindowsError: file C:\PROGRA~1\Autodesk\maya2014\bin\python27.zip\subprocess.py line 826: 6 #
run this exe file - is the only option dedline communication. but it pays to stdout data and how it is necessary to pull out. subprocess options except I have not found, but if there are other options will be glad to try them
anyone else encountered this problem? strange that in pure Python 2.7 running in windows all works, and there is no Maya 2014
i use:
Windows 7 + Python 2.7.9
Maya 2014 (Python 2.7.3)

I was just trying something similar couple of days back, connecting to Deadline via the command line submitter and getting
# File "C:\Program Files\Autodesk\Maya2013\bin\python26.zip\subprocess.py", line 786, in _make_inheritable
# WindowsError: [Error 6] The handle is invalid
error in Maya 2013.5. One workaround found here which does fix this issue is to pipe all the handles
p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
Hope it helps.

Related

Returning SAS ‘Return Code’ Aka %SYSRC to parent python script

I’m having trouble checking for errors in python’s subprocess. The subprocess is a sas program. Any wizards have any magic to share? I’d like to avoid searching the sas log for strings and instead rely on the return code.
I’m stuck w/ python 2.7 on a AIX server.
I’m able to invoke a sas program in a variety of ways using python’s subprocess module. I’ve successfully invoked a program using the check_output module, the Popen module or even just the call object. However, for the life of me I cannot get the return code!
Import subprocess
Subprocess.call([‘SAS’,’/path/program.sas’])
Or
Import subprocess
P = subprocess.check_output(“sas /path/program.sas”, stderr=subprocess.STDOUT, shell=True)
Print(p)
Or
Import subprocess
P = subprocess.Popen(“sas /path/program.sas”, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
proc.wait()
Standard_output, standard_error = proc.communicate*(
Print(proc.returncode)
Or
Import subprocess
Try:
output = subprocess.check_output(‘sas /path/program.sas’, stderr=subprocess.STDOUT, shell=true)
Except subprocess.CalledProcessError as exc:
Print(“Status : Fail”, exc.returncode)
Python 2.7 Subprocess
SAS Completion Status
In my case, I kept receiving a return code of 0 or ‘’. This was happening, because of my sas program. See, my program was nothing more than an invalid libname reference.
Libname x ‘blah’;
This was returning 0 when I expected 2. I added abortabend to my program a viola python returned 2.
proc = subprocess.Popen(“sas /path/program.sas;” shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
proc.wait()
standard_output, standard_error = proc.communicate()
print(proc.returncode)
Note that you may need to setup your autoexec and config vars or define them in your command.

IOError while parsing a XML file

I wanted to use Python and XML to easily create objects in my Autodesk Maya Scene.
As soon as I try to parse my XML file, I get this Error :
Error: IOError: file C:\Program Files\Autodesk\Maya2016\bin\python27.zip\xml\dom\expatbuilder.py line 922: 2 #
The code that I wrote is this one :
import maya.cmds as cmds
import xml.dom.minidom as xd
class readXML():
def __init__(self):
path = "mRigger/XML/arm.rig"
print path
xFile = xd.parse(path)
init = readXML()
I only get the problem if I run it in Maya (Python 2.7) but not if I run it in PyCharm
Try switching to an absolute path. Your Maya may be running from a different working directory than PyCharm. an IOError 2 usually means 'file not found'

Running locally blastn against nt db thru python script

I have a fasta file with sequence that I want to blast locally to 'nt' database dowloaded on my computer from ncbi website
I dowloaded blast 2.6.0.
In order to access blast from anywhere, I did:
gedit ~/.bashrc
export PATH=/usr/local/ncbi-blast-2.6.0+/bin:$PATH
then I did:
source ~/.bashrc
Then I downloaded 'nt' database (155.6GB) and stored it in /usr/local/blastdb
I want to run in python script this command:
from Bio.Blast.Applications import NcbiblastnCommandline
cline = NcbiblastnCommandline(query="/home/proprietaire/Desktop/JADE/stage_scripts/seq_error_fasta.fasta", db="/usr/local/blastdb/nt", evalue=0.001, out="blast_result_local.xml", outfmt=5)
But it is not working for a reason. Please help me figure out what I'm doing wrong. Thank you for your help.
EDIT:
'seq_error_fasta.fasta' : is my fasta file with 64 sequences that I want to blast to 'nt' database.
My 'seq_error_fasta.fasta' contains sequence loaded with error like S, J, X so I want to blast them to 'nt' db in order to get the closest better sequence
I found out that I need to format the nt database dowloaded from ncbi so I did this:
makeblastdb -dbtype nucl -in nt
Then I added this after my cline variable in my python script:
stdout, stderr = cline()
The script is running but unfortunately I'm getting this error now:
Bus error (core dumped)
I think it's a ram memory problem so I thought that I need to shorten 'nt' db by taking only the bacteria sequence. I looked on NCBI for a whole bacteria only database but there is multiple database of different species like more then a thousand.
I also tried blast online using this script:
f = open('output_blast.xml','w')
for rec in SeqIO.parse(open("seq_error_fasta.fasta"), 'fasta):
result_handle = NCBIWWW.qblast("blastn", "nt", rec.format("fasta"), format_type="XML", alignments=1, perc_ident=95, expect= 0.001)
f.write(result_handle.read())
f.close()
but this only doing one query sequence and returning all hits, althought I specified 1 hit and 95% of identity.
This is driving me crazy lollll Please help
Download NCBI nr database:
$ mkdir db
$ cd db
$ wget ftp://ftp.ncbi.nlm.nih.gov/blast/db/nr*
Run blast:
import io
import shlex
import subprocess
BLAST_OUTFMT6 = """\
'6 qacc sacc pident length mismatch gapopen qstart qend sstart send evalue bitscore qseq sseq'\
"""
BLAST_OUTFMT6_COLUMN_NAMES = [
'query_id', 'subject_id', 'pc_identity', 'alignment_length', 'mismatches', 'gap_opens',
'q_start', 'q_end', 's_start', 's_end', 'evalue', 'bitscore', 'qseq', 'sseq',
]
def blastp(sequence, db, evalue=0.001, max_target_seqs=100000):
system_command = (
'blastp -db {db} -outfmt {outfmt} -evalue {evalue} -max_target_seqs {max_target_seqs}'
.format(db=db, outfmt=BLAST_OUTFMT6, evalue=evalue, max_target_seqs=max_target_seqs)
)
cp = subprocess.Popen(
shlex.split(system_command),
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True)
result, error_message = cp.communicate(sequence)
if error_message.strip():
print("Error: {}".format(error_message))
return result
if __name__ == '__main__':
result = blastp('AAAAAAAAAAAAAA', db='/path/to/db/nr')
print(result)

Unexpected EOF, using slate to parse PDF file on Python 2.7.12

I picked up O'Reiley's Data Wrangling with Python by Jacqueline Kazil and Katherine Karmul. In ch.5, pg.94, I'm running the following code.
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf) as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page
I'm using Windows 10, Python 2.7.12 , running slate 0.5.2, pdfminer 20140328 and successfully installed pip. I got the following result:
File "C:\Python27\lib\site-packages\pdfminer\psparser.py", line 215, in fillbuf
raise PSEOF('Unexpected EOF')
pdfminer.psparser.PSEOF: Unexpected EOF
I only know that EOF means 'end of file' and no more data can be read from data source. Does anybody have an idea as to what happened?
If anybody would like to see what file I'm trying to parse, it's right here:
https://github.com/jackiekazil/data-wrangling/tree/master/data/chp5
This solved it for me: https://stackoverflow.com/a/18262661/6843645
Your code would be:
import slate
pdf = 'EN-FINAL Table 9.pdf'
with open(pdf, 'rb') as f:
doc = slate.PDF(f)
for page in doc[:2]:
print page

Crash on Nite initialisation in python program written using primesense2.2.0.30-5

I am using Ubunut 14.04 and have installed OpenNI 2.2, NITE 2.2 and primesense2.2.0.30-5 (https://pypi.python.org/pypi/primesense/2.2.0.30-5)
The sample program mentioned at the above site works quite well however when I am trying to use initialize nite2 the program crashes.
Here is the code:
from primesense import openni2, nite2
openni2.initialize() # can also accept the path of the OpenNI redistribution
nite2.initialize()
if (nite2.is_initialized()):
print "nite2 initialized"
else:
print "nite2 not initialized"
dev = openni2.Device.open_any()
print dev.get_sensor_info(openni2.SENSOR_DEPTH)
depth_stream = dev.create_depth_stream()
depth_stream.start()
frame = depth_stream.read_frame()
frame_data = frame.get_buffer_as_uint16()
depth_stream.stop()
openni2.unload()
Error Report :
Traceback (most recent call last):
File "test.py", line 4, in <module>
nite2.initialize()
File "/usr/local/lib/python2.7/dist-packages/primesense/nite2.py", line 81, in initialize
("\n ".join("%s: %s" % (dir, ex) for dir, ex in exceptions)),)
primesense.utils.InitializationError: NiTE2 could not be loaded:
/home/user/project/kinect/NiTE-Linux-x64-2.2/Samples/Bin/libNiTE2.so: /home/user/project/kinect/NiTE-Linux-x64-2.2/Samples/Bin/libNiTE2.so: undefined symbol: niteDumpUserTrackerCalibrationDataToFile
OpenNI2-FreenectDriver: Closing device freenect://0
I want nite python bindings for user tracking and hand tracking . Did anyone done it before successfully
A workaround is to comment the following lines in file _openni2.py from the primesense python bindings:
global _niteDumpUserTrackerCalibrationDataToFile
_niteDumpUserTrackerCalibrationDataToFile = dll.niteDumpUserTrackerCalibrationDataToFile
_niteDumpUserTrackerCalibrationDataToFile.restype = NiteStatus
_niteDumpUserTrackerCalibrationDataToFile.argtypes = [NiteUserTrackerHandle, NiteUserId, ctypes.c_char_p]
Also, make sure you have a copy/symlink of both the NiTE2 library and folder (Redist/NiTE2 in the archive) in the same directory as your python script.