PyInstaller not working on simple HelloWorld Program - python-2.7

So I am running on 64-bit Windows 7, and I set up Pyinstaller with Pip and PyWin32. I have python 2.7.
I made a simple hello world Program with this code
print "hello world!"
I put the file in the same directory as PyInstaller, and ran this code in the command prompt
pyinstaller.py helloWorld.py
Yet, when I try that, I get this error message:
Error loading Python DLL: C:\PROGRA~1\PYINST~1.1\build\HELLOW~1\python27.dll (error code 126)
What am I doing wrong and how do I fix this?

Run with the -F flag to produce the standalone exe:
pyinstaller -F helloworld.py
It will output to dist/helloworld.exe
NOTE this is a different location to when -F is not used, be sure to run the right exe afterwards.

Thanks #tul! My version of pyinstaller put it to dist\helloworld.exe though!
If you start it from C:\Python27\Scripts... that'll be C:\Python27\Scripts\dist... as well!
But whereever you have it, I recommend putting a batch file next to your .py to be able recompile any time with just a click:
I set it up so there is nothing but the .exe at the .py location and the temporary stuff goes to the temp dir:
#echo off
:: get name from filename without path and ext
set name=%~n0
echo ========= %name% =========
:: cut away the suffix "_build"
set name=%name:~0,-6%
set pypath=C:\Python27\Scripts
set buildpath=%temp%
if not exist %name%.py (
echo ERROR: "%name%.py" does not exist here!
pause
exit /b
)
%pypath%\pyinstaller.exe --onefile -y %~dp0%name%.py --distpath=%~dp0 --workpath=%buildpath% --specpath=%buildpath%
I name it like the .py file plus "_build" and cut away the suffix in the batch script again.
Voilà.

Related

How can I debug a C program installed using guix?

I installed flatpak using guix, but it segfaulted on startup. I wanted to debug it, but guix installs a wrapper script for flatpak, so I get this error when trying to run it under gdb:
"/home/user/.guix-profile/bin/flatpak": not in executable format: file format not recognized
and I tried to edit the wrapper script to call gdb, but this wrapper script is not even editable by root, because it is owned by root and has read-only permissions.
Simply copy the script to your current working directory:
cp /home/user/.guix-profile/bin/flatpak .
Mark it as writable:
chmod +w flatpak
Edit the script with your favourite text editor, to replace the string exec -a with exec gdb --args.
And finally, run it with any arguments you provided before, when it misbehaved:
./flatpak remote-add flathub https://flathub.org/repo/flathub.flatpakrepo
In this particular case, this wasn't immediately super-useful, because a debug symbol output hasn't been built for this package. But at least I could get a backtrace out of gdb.

command prompt appears than immediately disappears

I encountered this problem after following a python tutorial on Youtube about creating text files. The instructor had us type in the following code to start:
def createFile(dest):
print dest
if__name__ == '__main__':
createFile('ham')
raw_input('done!')
We had created a folder on the desktop to store the file 'ham' in. But when I double clicked on 'ham' the command prompt window popped on then in a flash it popped off. I am an obvious beginner and I don't know what is going on. Can anyone explain this to me?
You can open command prompt then navigate to python interpreter
directory and run your program by typing python /diretory/to/your/program.py for
example if you have a program named test.py in the directory c:/python and you want to
run it and you have python interpreter installed in C:/python2.x/ directory
then you should open command prompt and type in
cd c:\python2.x\
then you should type
python c:/python/test.py
and perfectly it will work
showing you your program output .

subprocess.call() not working Python

I am trying to pass arguments to an executable written in C from my script, however, the program is not executed and no console window appears which appears when the executable is run.
I have tried to run the executable using os.system() and subprocess.call(), both return 0 which I think means the command executed successfully but my executable doesn't run.
What am I missing here?
subprocess.call(["C:\Program Files (x86)\Hello\myApp.exe", "-i abc.txt -o xyz.pdf"],shell=True)
os.system('"'+'C:\Program Files (x86)\Hello\myApp.exe -i abc.txt -o xyz.pdf'+'"');
I have tried running without arguments as well still the program doesn't execute.
Unless myApp.exe is a shell command such as dir; don't use shell=True on Windows.
If you use a list argument then each list item should be a separate argument for your program:
from subprocess import check_call
check_call([r'C:\Program Files (x86)\Hello\myApp.exe', #NOTE: `r''` literal
'-i', 'abc.txt', '-o', 'xyz.pdf'])

Try to execute command line codes from c++ linux

I tried the following code, to communicate with the command line from c++ code.
#include<iostream>
#include<cv.h>
int main()
{
system("gnome-terminal");
system("cd");
}
The gnome-terminal command is executing fine. After I close the terminal, when am expecting the cd to execute, however, is not happening. Could you please help me and point out the reason? Thanks. I was expecting the function to make the cmd go down to the home directory
, but it did not. am working in linux
I tried it even by removing gnome. simple cd is not working. am I doing something rong>?
If I try ls, it seems to be working fine!
My main aim is to open a new terminal, and execute commands on that new terminal through the present program that opened the new terminal. Could you please tell me how I can achieve this??
If you want to run a program and wait for it to finish before executing next line, take a look at this page and example code here: http://www.thegeekstuff.com/2012/03/c-process-control-functions/
But if you want to run gnome-terminal and execute a command in newly created window, do this:
system("gnome-terminal -x sh -c 'cd /tmp ; ls -la'");
The system function creates a shell child process to execute the specified command.
cd is a shell command which changes the current working directory of that shell process only.
So the child's cd probably works fine, but it has no effect on your C++ program, which is a different process.
Instead, you probably want to look at the Linux system call chdir.
Thanks for your help!! This command worked perfectly fine from this link
https://superuser.com/questions/198015/open-gnome-terminal-programmatically-and-execute-commands-after-bashrc-was-execu
gnome-terminal -x sh -c 'command1; command2; exec bash'
and I entered the respective commands in the new window. But to change the working directory in the shell am working o, I haven't still figured that out.

What needs to be done to get a distributable program from Eclipse?

I’ve produced a C++ program in Eclipse running on Redhat, which compiles and runs fine through Eclipse.
I thought that to run it separately to Eclipse you use the build artifact which is in the directory set via the project’s properties.
However this executable doesn’t run (I know it’s an executable as I’ve set it to be an executable via the project’s properties and it shows up as such via the ls command and the file explorer).
When attempting to run it using the executable’s name, I get the error:
bash: <filename>: command not found
When attempting to run it as a bash file:
<filename>: <filename>: cannot execute binary file
And when running it with "./" before the file name, nothing happens. Nothing new appears in the running processes and the terminal just goes to the next line as though I’d just pressed enter with no command.
Any help?
You've more or less figure out the first error yourself. when you just run <filename> , it is not in your PATH environment variable, so you get "command not found". You have to give a full or relative path when to the program in order to run it, even if you're in the same directory as the program - you run it with ./<filename>
When you do run your program, it appears to just exit as soon as you start it - we can't help much with that without knowing what the program does or see some code.
You can do some debugging, e.g. after the program just exits run echo $? to see if it exited with a particular exit value, or run your program using the strace tool to see what it does (or do it the usual way, insert printf debugging, or debug it with gdb)