I've been stuck on a peculiar error for several hours, searching for solutions in Google and failing, probably because the problem is so specific, but it actually has broader implications, which is why I've been trying hard to fix it.
I am using Python 2.6 and can use the subprocess.call() to run a program called STAMP in the vanilla Python terminal, or even the iPython terminal as such:
>>>Import subprocess
>>>subprocess.call('stamp')
That works fine, but when I execute the same thing via sublime text 2 (ST2) using it's sublimeREPL plug-in for python or iPython (Tools>sublimeREPL>Python>...) it fails with the following error:
> Traceback (most recent call last): File "<stdin>", line 1, in
> <module> File "<string>", line 27, in <module> File
> "/usr/lib64/python2.6/subprocess.py", line 478, in call
> p = Popen(*popenargs, **kwargs) File "/usr/lib64/python2.6/subprocess.py", line 642, in __init__
> errread, errwrite) File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
> raise child_exception OSError: [Errno 2] No such file or directory
Which is the same error it gives when you call a program that is not installed on the system. It seems paradoxical that this error does not appear for any other installed programs/commands that I've tested other than 'stamp' (so you would think sublimeREPL is working fine), and yet running subprocess.call('stamp') does work in the native python terminal, as well as iPython (so you would think stamp is working/installed fine). The only clue I had in mind was that I had to install stamp using g++
Summary:
subprocess.call('stamp') works in a native python terminal
subprocess.call('stamp') does not work in ST2's sublimeREPL python terminal
subprocess.call() seems to work fine in both sublimeREPL or native python terminal
Extra info:
Python 2.6.3
Installation procedure for stamp:
Step 1: Install the GNU Scientific Library.
Download from http://www.gnu.org/software/gsl/
Add the 'include' and 'lib' directories to your PATH.
Step 2: Compile the STAMP code.
Use a command such as the following:
g++ -O3 -o stamp Motif.cpp Alignment.cpp ColumnComp.cpp \
PlatformSupport.cpp PlatformTesting.cpp Tree.cpp \
NeuralTree.cpp MultipleAlignment.cpp RandPSSMGen.cpp \
ProteinDomains.cpp main.cpp -lm -lgsl -lgslcblas
Note: if the GSL library is not in the PATH, add the appropriate
directories using the -L and -I compiler options.
Step 3: Test it out!
Converting my comment to answer form so that it's clearer that the problem was solved:
PATH is not set inside the sublimeREPL terminal. If you provide the full path to the stamp executable, subprocess.call will work fine.
Related
I am trying to run this line of code to generate a report using pylatex:
doc.generate_pdf(report_name, clean_tex=True)
This works well to generate a pdf file without any error when I use Spyder and Jupyter Notebook to execute the program, but when I try to use Crontab to automate my task by executing the exact same py file every day,
0 6 * * * cd /Users/me/my_folder && /anaconda3/bin/python3 MyProgram.py
the following error occurs via terminal mail:
Traceback (most recent call last):
File "MyProgram.py", line 255
doc.generate_pdf(report_name, clean_tex=True)
File "/anaconda3/lib/python3.7/site-packages/pylatex/document.py", line 299, in generate_pdf
'No LaTex compiler was found\n'
pylatex.errors.CompilerError: No LaTex compiler was found
Either specify a LaTex compiler or make sure you have latexmk or pdfLaTex installed.
I have spent hours searching for solutions online but still cannot fix the bug. So I would like to get some help. Thanks in advance.
I recently added a tool to my makefile's toolchain that is written in python. It processes .json input and outputs some assembly data, and when in run the python tool from the console (e.g. python xxx.py -o yyy.s zzz.json) it works quite well. However when the same script is run from within the makefile, suddenly package imports fail (concretly spoken those I installed using pip).
The makefile outputs the following error:
Traceback (most recent call last):
File "tools/pyset2s.py", line 2, in <module>
import pymap.tileset
File "/cygdrive/d/Hacking/__Violet_Sources/tools/pymap/tileset.py", line 3, in <module>
from . import image, palette, agbimg
File "/cygdrive/d/Hacking/__Violet_Sources/tools/pymap/image.py", line 3, in <module>
import png
ImportError: No module named png
make: *** [makefile:135: bld/map/tileset/gfx_maptileset0.s] Error 1
make: *** Waiting for unfinished jobs....
The only cause of this problem I figured so far might be, that the package (in this case PyPng, but I suppose it will also fail on the other ones (being Pilow and numpy) was installed while being in administrator mode (I am working under Windows and using a cygwin shell for the make call). However reinstalling the package did not work, since I am told, that the requirements are already satisfied. I also do not know who to promote my IDE (I am using Netbeans) to use adminstrator rights when running the make command.
Is there any solution to that?
I have a socket server python script and it runs good on linux, but when compiled to binary on Linux using pyinstaller, it runs into wired situations says
File "<string>", line 426, in <module>
File "<string>", line 49, in __init__
NameError: global name 'exit' is not defined
environment:
Linux 2.6.32, python2.6.6, pyinstaller 2.0
here is a simple test script that could recreate this error
program:
exit.__class__
compile commands:
pyinstaller.py -F --noconsole --out=/output_folder/ /source/path
which expect to print out:
<class 'site.Quitter'>
hope someone could give me a clue, a shared library thing?
solved, explicitly use sys.exit(1) to skip this.
I get a warning message while trying to create exectable file using pyinstaller. This warning appeared after installing Pillow. Previously i nevre got any warnings and was able to make it through.
the warning i get by pyinstaller is:
7314 INFO: Analyzing main.py
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/hook-PIL.Image.py:14: RuntimeWarning: Parent module 'PyInstaller.hooks.hook-PIL' not found while handling absolute import
from PyInstaller.hooks.shared_PIL_Image import *
Also when i tried to run the executable's exe/consol version of my code that lies inside the dist folder created by the pyinstaller (dist/main/main), these are displayed..
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/PIL.Image", line 53, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 276, in load_module
exec(bytecode, module.__dict__)
File "/Users/..../build/main/out00-PYZ.pyz/FixTk", line 74, in <module>
OSError: [Errno 20] Not a directory: '/Users/.../dist/main/tcl'
logout
[Process completed]
so, i tried by uninstalling pillow, installing tk tcl dev version. And then installed pillow. Even that didnt helped.
I also tried reinstalling pyinstaller,. didnt help too
Update 1:
It seems Pyinstaller.hooks.hook-PIL.py file was missing in the Pyinstaller/hooks directory. And it was missing on all platforms(Mac, windows and linux). This is the warning/error message that i get on windows, which is the same i got on mac and on linux.
Later i found a link which said, its just to need Python import machinery happy. so i created as said so. Then i dont get the same error on all platforms, But on mac i still get the PILImagePlugin,Image and FixTk errors
Solution for tcl:
I found what was going wrong,.. Every problem that i faced on OSX was the OS itself(exactly the macport). Python by default comes with the mac OS. And this version of python may be useful for just learning basic python, but is not suitable for Development purpose.
Installing brew's python helped. I followed this SO link. After doing these i was still getting errors. Later i had to change the paths on /etc/paths. Basically rearranging them should work. But still then i wasn't getting it right.
Then i had to change the .bash_profile, which worked for most users, But still i was getting mac's version of python and pip, not the brews version of python.
Finally i had to restart the machine for a couple of times and do the /etc/paths and .bash_profile steps repeatedly to get the system wide effect to accept brews version of python and pip
Solution for PIL:
just adding a file called hook-PIL.py with an empty content would serve the purpose. I found a link which was having the hook files content of pyinstaller.
The location to create
for mac : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/hooks/ Actually for mac this step wouldn’t be required. When we install python through brew and change the path, everything that you try to install later either through pip install or from source packages tend to choose a different path. And everything will be taken care of.
for windows:C:\Python27\lib\site-packages\PyInstaller-2.1.1.dev0-py2.7.egg\PyInstaller\hooks
**Please check if this is a valid path on your machine before creating the file and then create the file. And im not sure or i don't know if just adding an empty file is the right way. But it worked for me
I'm running Windows 7, and using python version 2.7.
I've been trying to use pygraphviz, but whenever I use G.layout() on a graph, I get the error message;
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
G.layout()
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout
data=self._run_prog(prog,' '.join([args,"-T",fmt]))
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog
runprog=r'"%s"'%self._get_prog(prog)
File "C:\Python27\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog
raise ValueError("Program %s not found in path."%prog)
ValueError: Program neato not found in path.
I know, however, that the Graphviz files are installed, and the directory is in my path (I've manually gone and added it).
I've tried the simlink solution given here but all I get when I enter that into the command line (administrator mode) is a message saying it is not recognized as an internal or external command, operable program, or batch file. I'm not experienced enough to know whether there's something I'm failing to do with that though.
Is there something I can do to make this work?
I had the same problem with conda. Apparently there is something wrong with the libraries. This comment in here worked for me:
https://github.com/conda/conda/issues/1851#issuecomment-314924385
In the Anaconda prompt do both:
conda install -c anaconda graphviz
and
conda install -c anaconda python-graphviz
Then import graphviz will work.