I created an main.py
Where the code is on.system('program.exe')
And I compiled it with auto-py-to-exe as one file added the program.exe as add files when I execute it says program.exe is not recognized as internal or external error lease help thank you 😊
The problem is too complex for me please help
You are not supplying a ton of context but I am pretty sure this is because your compiled Python script cannot find program.exe. And this is probably because the "current working directory" is not the one containing program.exe. An easy solution would be to specify the complete path like C:\path\to\program.exe.
Related
My terminal is running python 2 so when I run my python file the program fails.
So basically I am new to programming and trying to create a small python script to help me auto create folders. I also want to give the script to colleges so that they can use it on their systems too.
I know that I can run my file in terminal by using "python3 myfile.py" and it will work, but that's too much off a mission to do for my colleges and as my colleges are not familiar with code or terminal for that matter, I wanted to create an executable file so that they just click to open type a few answers to the promoted question and boom folders created.
This is where I run into a problem, I have "#!/usr/bin/env python3" at the top of my file but when I run the script IDLE opens up and it just shows the code I have written but doesn't seem to run the actual script I wrote. Am I doing something wrong?
I also then though perhaps I could just use the terminal to run the file as it is now executable, so I go into terminal and enter "myfile.py" and the program runs but in python 2 so my script fails as it is in python3. So another question would be is there a way to code into my python file, when running this file make sure you use python3? as I would want this to work on all colleges system without them having to write out anything in terminal?
Sorry for the long explanation but any advice would be greatly appreciated.
Thank you in advance
When you are on windows you can just create a .bat file where you write: python3 myfile.py in it.
Both files have to be in the same directory.
If you want to have a .exe you can also use py2exe.
You could also try just #!/usr/bin/python3 without env.
More here.
I am not sure what I am supposed to be searching, because everything I have been trying to look up has not really given me the answers that I need.
If anyone can point me in the right direction of exactly what I should be looking at, I would greatly appreciate it. Basically, I want to know the best way to go about making a python program which I can distribute (not publicly).
Once someone has the file they run a script, or run the make command, and the result of this would be that the user can invoke the program from within any directory on the computer by just typing the name (and passing args) in the terminal.
I only know of one way to do this, which I believe is the wrong way. My idea was something as follows:
1.) A main folder, let's call it Ghoul. It would contain 3 files:
setup.sh
ghoul.sh
ghoul.py
2.) The user would have to run setup.sh, which would make ghoul.sh an executable and it would change the name to ghoul and then I would move it to /bin
3.) Within the ghoul file which is now in /bin, the file itself would contain "python /home/user/Ghoul/ghoul.py $#" And this would allow the program to run from any directory just by typing "ghoul"
I hope it's clear what I am trying to accomplish, I know this can't be the appropriate way of doing this. What should I be looking up and reading on to accomplish this? I would like to know how I can do this on Ubuntu and if also ..Windows.
I am also interested if I can limit the "ghoul" command to work only in the Ghoul directory, but of course in any directory that is within the Ghoul directory instead of from within any directory on the system.
Thank you.
On Unix like systems
#! /usr/bin/env python
in the very first line of your chmod +x script file will make it executable from the current directory using ./filename
If you want completely straightforward execution from anywhere you can put it on the path somewhere however you choose.
On windows its more complicated, if you want commandline execution the default install should give you the ability to execute
myscript.py
If its in your path. to drop the .py you need to get .py into the PATHEXT variable. Alternatively if it neds to be distributed to someone without any python install check out www.py2exe.org
Some programs can be executed from anywhere with a single one-word command. An example of this is youtube-dl, which is a python program that can be executed with the simple command youtube-dl [input]. As far as I have understood, this is simply because there exists a file called /usr/bin/youtube-dl, and /usr/bin is in PATH. However, I do not understand what I have to do to make something like this myself. Right now, I have a python project called testproject that includes a python program like this:
~/testproject/files/myownprogram.py
What do I have to do to make this a binary executable such as youtube-dl?
I know I can make an alias mop="python ~/testproject/files/myownprogram.py", and this is also what I have done, and it works fine. That is, I can write $ mop, and successfully run my program.
But for curiosity's, and learning's, sake, I want to know how to make a file such as the /usr/bin/youtube-dl file, removing the need for aliases.
I find this hard to find information about in search engines...
Any help is greatly appreciated! :-)
Edit:
My question differs from the one marked as duplicate, in that I'm not looking to execute it as a .sh-script. I simply want to execute it as a suffix-less one-word command, similar to all the other executables that are in /usr/bin. :-)
Ex.: $ myown should run my program, without the need for aliases or writing ".sh" or ".py" at the prompt. That is, I want to have a file /usr/bin/myown that somehow runs my testproject at the simple command myownfrom anywhere.
The applications are being executed "from anywhere" because the system has a specific hierarchy of places it looks for these files (the current directory, then the system path). So, it knows to look in /usr/bin because that's in your system path.
As to ensuring it to use python when it's executed, you should add the following to the top of the file (check out some python application source code and you'll see this):
#!/usr/bin/env python
This tells the system to execute the script using the systems "python" command.
Is it possible to get .py text file from .exe file generated with cx_Freeze? If yes, how can I prevent it when I generate exe? I don't want that somebody see my python code. Of course anybody will have access to bytecode, but it much harder to disasemblate it.
Seems like using cython will make it impossible to get script back.
I have created a working GUI program (using tkinter), but when I try to compile it using pyinstaller (py2exe only works for python 2.6 and I used 2.7 for the program), it doesn't work. I have 2 files: program.py, and data.xml. The program uses the xml document to retrieve information and display it to the window. I have looked all over, but no one seems to have had a similar problem, and the pyinstaller documentation is useless. the command I used was
python pyinstaller.py -w -mdata.xml -nProgram program.py
It appears to make the spec file fine, but generates an error with a large traceback upon build:
pyinstaller.utils.winmanifest.invalidManifestError: Invalid root element <items> - has to be one of <assembly>, <assemblyBinding>, <configuration>, <dependentAssembly>
and quits the build process. This is the first time I have tried to build an executable for a project, so I'm kind of shooting in the dark here. Did I forget to do something, or did I just find a bug in pyinstaller's program?
Normally I wouldn't answer my own question, but I have solved the issue and I think others should know about this. When creating your program and using an xml with it, you must have the root tag (the first one) as <assembly>. Not sure why, but it works when I do that. also, don't forget to use the --hidden-import=Module command if you imported anything into your program.