I have a project written in Python 2.7 and PyGTK, with py2exe for compiling. I have two modules, "Launchpad.py" and "RegistrationScreen.py". I need to open RegistrationScreen.py from Launchpad.py.
I am using the following code currently:
def open_registration(event, data=None):
subprocess.Popen(["python", "RegistrationScreen.py"])
This works fine when I test - the window is opened without the shell window opening.
However, when I compile using py2exe, I get the following log error on executing the created application.
Traceback (most recent call last): File "Launchpad.py", line 26, in
open_registration File "subprocess.pyc", line 672, in init
File "subprocess.pyc", line 882, in _execute_child WindowsError:
[Error 2] The system cannot find the file specified
How do I fix my code so py2exe will compile it correctly? Is there another way I can open the RegistrationScreen.py module's window from Launchpad.py, that won't throw errors in the final .exe file?
The problem is the path. RegistrationScreen.py is (probably) compressed inside dist/library.zip, but your code that calls it is looking for it in dist/RegestrationScreen.py.
I don't know what the best solution to this is... py2exe is kind of a pain for accessing files.
Also, you probably don't want to be doing subprocess.Popen(["python", "RegistrationScreen.py"]) because you can't guarantee your users will have python installed and accessible systemwide. If you really need a separate process, then maybe you should run py2exe on RegistrationScreen.py individually to create a separate .exe, and then include that in the dist folder of your main .exe?
I know that's somewhat convoluted, but it would probably work. And as I said, there might be a better way.
Related
I'm using pyinstaller to try and turn a pygame program into an EXE file, and the pygame library runs fine but PyOpenAl (an external sound library I'm using) just won't import correctly. Every time I run the EXE I get this error:
File "snd_music_player.py", line 5, in __init__
self.music = oalOpen("music/title.ogg")
File "openal\__init__.py", line 836, in oalOpen
File "openal\__init__.py", line 113, in _no_pyogg_error
File "openal\__init__.py", line 58, in _err
openal.OalError: You have to set up pyogg in order to use this function. Go to https://github.com/Zuzu-Typ/PyOgg to get it
Even though PyOgg is very much installed. I tried running the program on another computer, and a new error popped up that apparently PyOpenAL wasn't included either. I've tried using --hidden-import but it doesn't seem to work. Is there any other way to properly force PyOpenAL and PyOgg to be packaged?
I created an installer file using nsis. After running the programme on my system, it worked flawlessly but when installed on third party system, it complained on launching the app.
Traceback (most recent call last):
File "Classify.py", line 20, in <module>
File "tkinter\_init_.py", line 2109, in wm_iconbitmap
_tkinter.TclError: bitmap "D:\Users\Engr M2J\Documents\GitHub\HAM1000-Image-Classifier\logo.ico" not defined
I know this is where the error is coming from;
root.title("HAM10000 Image Classifier by Engr. Sule Muhammed Abba- BookNowNow Code version 1.1.0")
root.iconbitmap(r'D:\Users\Engr M2J\Documents\GitHub\HAM1000-Image-Classifier\logo.ico')
it is actually referencing my computer path instead of it to be relative. This is the only way I could get the icon to load by using it direct path. whenever I use the below code, I get the error that follows;
root.iconbitmap('logo.ico')
I get this error
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "logo.ico" not defined
Please assist
Here are the steps taken to solve the problem.
I printed the working directory.
print(getcwd())
I then copied all code files to this directory
By doing this, I was able to load the icon using
root.iconbitmap(r'logo.ico')
My new software now runs seamlessly on different systems without any complain.
Any better solution is welcome but this will work perfectly.
I am writing a code which I want to have details to its own directory. e.g. C:\Users\User\Desktop\helloworld.py
Is there a way to find it from within the program using pywin32 or any other module?
If so, once I turn it into .exe using py2exe will it still be able to find it's own directory(C:\Users\User\Desktop\dist\helloworld.exe)
I tried the following code:
print os.path.dirname(os.path.realpath(sys.argv[0]))
This works but once I turn it into a .exe file it doesn't manage to run.... What other solutions can there be?
The error I get in the log file is the following error:
Traceback (most recent call last): File "finddirectory.py", line 4, in EOFError: EOF when reading a line
You can find that information on the py2exe wiki:
http://www.py2exe.org/index.cgi/WhereAmI
Okay I am newer to python and have been researching this problem but I can't find anything like it so I am not sure what is going on.
I am creating a program that involves sage and it has a message cue. We have this set up on a development machine, so I know it works but I was wanting to set it up on my own computer so I could get a better understanding of how it all works and make it easier to develop for myself.
To start up sage, we run a script that calls sages main binary file and passes it an executable .py file. (./sage/sage ./sage_server.py) This creates an error in the sage_server.py file:
Traceback (most recent call last):
File "./sage_server.py", line 23, in <module>
from carrot.messaging import Publisher
ImportError: No module named carrot.messaging
But whenever I run that file just in the terminal (./sage_server) the import works fine and isn't until line 27 that there is an error when it tries to import something from sage.
Does anyone know what would cause the error when it is being called by something else? I am very lost as to what would be causing this.
Sage has its own python, separate from the system libraries. This "carrot" module, whatever it is, must be installed in whatever python ./sage_server.py uses, but not in Sage.
You should be able to use either
[your-sage] -sh
to start up a Sage shell and use easy_install, or you could get whatever carroty package you're using, find its setup.py file, and then run
[your-sage] -python setup.py install
where obviously your-sage is the path to your sage.
Things get a little trickier if the install process isn't setup.py-based.
I've recently come back to a project having had to stop for about 6 months, and after reinstalling my operating system and coming back to it I'm having all kinds of crazy things happen. I made sure to install the same version(2.6) of python that I was using before.
It started by giving me strange tkinter error that I hadn't had trouble with before, the program is relatively simple and the 2 or 3 bugs that were left when i quit, I had documented and weren't related to the interface.
Things got even weirder when the same error would pop up even after I had removed the offending section of code. In fact, the traceback pointed to a line that didn't even exist in the module it was referencing, eg: line 262 when the module was only 200 lines long.
After just starting a completely new file for the main module and copy/pasting it finally recognized that the offending code was gone and I stopped getting the error only to find that any updates to the code I made in another module didn't show up when I restarted the program through the shell. (I didn't forget to save.) After fiddling with this, of course, the old interface error came back, only in a different section of code that had been working previously.
In fact, if I revert back to the files I had six months ago, the program works fine. As soon as I change anything in the main module, however, the interface bug comes back.
Here's the original error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\PyStuff\interface.py", line 202, in dispOne
__main__.top.destroy()
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1938, in destroy
self.tk.call('destroy', self._w)
TclError: can't invoke "destroy" command: application has been destroyed
I'm guessing something else is going on here other than my own poor programming. Anyone have any ideas?
Edit: Thinking back, I believe I read something about it being a bad idea to run Tkinter programs through IDLE's shell, and it appears, at least, that the TclError has vanished if I instead start the main module by double clicking the .pyc file. Perhaps my problems were just a combination of that plus the timestamp/PYTHONPATH issues mentioned below by Chris Atlee and Vlad?
I've had something similar happen. The cause for my problems was that my source control software (hg) was setting the date of files to a date in the past. Because of this, python chose to use previously generated .pyc files which had newer timestamps.
The solution was to delete all the .pyc files before testing the code.
Check your PYTHON_PATH variable, you probably have an older version of the file.
Also start your python interpreter and type the following commands to check the path:
import sys
print sys.path
Take a careful look at the output and make sure you don't have any old directories sitting there.