I have a question for you that is making me crazy.
I am working on my python package. I'm building my package using hatchling and pyproject.toml and I have also three GUI targets.
To make them I'm using the project.gui-scripts section in the project files and indeed, three exe files are included in the scripts directory after the package installation.
All of a sudden two out of three exe files are not starting at all. If you execute it from CMD, you don't get any error message, nothing. I said all of a sudden because in the past they all used to work.
The third one, instead is still working nicely.
Do you know if there is anything I can do to check what's going wrong? Can I debug those exe files?
Thanks in advance,
Related
I created a data-miner GUI for twitter with kivy and am currently having a lot of trouble turning it into an exe. I tried following this video and import glew and sdl2 into my spec but after doing pyinstaller main.spec, my executable still would not open.
Is it because I have more than one files and folders for my program (here is the link to the github repo for my project), if so, how do you deal with that?
In addition, if I manage to success create a working exe, how do I create an exe installer that other people can use to install the executable?
Making an executable from a complex script like yours may become quite frustrating because of its dependencies. But I'm giving you a brief guide about what you need to follow to achieve your goal.
Create your main.spec file with console-mode enabled to see the exact error message for the app. (make sure to remove --noconsole from PyInstaller command or set console=True in spec file). Also use --no-upx in the build command to remove compression from output file (this helps with omitting some DLLs which may cause issues).
You need to make sure that every external module you used can pack correctly. I don't think you get any problem with either Kivy or Tweepy. But if you get any missing import error, try to check the solution for each one by searching the pattern [module] pyinstaller.
Your app has external resources like images, files, etc., which must be added to the packed executable and load properly. I wrote an answer about this here.
If you want a standalone executable, you need to use -F with PyInstaller command, which is more robust than using an installer to gather files in one directory mode.
I have been using PyCharm since I began learning Python because of its amazing UI that helped me learn a great deal about the language. As I progress into more advanced projects, I am beginning to prefer using a text editor / command line combo so that I can build my own venv's and have better access to source control. My question is, how does PyCharm manage custom local packages that I created so that I can import them wherever I want in the directory? For instance a project that I have built exclusively in PyCharm that runs will raise numerous import errors when trying to run that same project in VS code, or even a command line shell (yes I did have the PyCharm created venv activated before running on both attempts). For further examples, here is the project structure I am confused about:
RootDirectory
package_1_folder
__init__.py
pckg_1_class.py
program_using_pckg_1_folder
class_using_pckg1class.py
venv
The above structure has no issues being imported and used in PyCharm, however VS code / Sublime when used with command prompt / gitbash will raise either an ImportError or a ModuleNotFound error. I have even gone as far as adding the desired packages to my laptops windows PATH, using sys.path.append (I know this is not good practice I was only trying to get it to work), and even modified the .pylintrc file with the project path with no success. Any help explaining why these errors are happening would be greatly appreciated :)
NOTE:
I have been able to use the packages in VS code as long as the program importing the module is located at the root directory level, but not in its own folder in the root directory. Again, this statement WILL work in PyCharm, I just want to know how PyCharm is able to achieve this.
After numerous attempts to locate how the system was keeping tack of module within the IDE, I found that my answer was not visible from the IDE. I found a .idea folder in my root directory that contains a few .xml documents that manage the directory including where to read modules from.
I have built a Cx Freeze exe from python code. Code worked fine. I recently modified one .py file and rebuilt the exe. Dragged the entire build directory over to another computer for use and it looked as though it was using an older version of the code. Rebuilt, retried. Same thing.
Ended up moving over the new updated python file to the other computer and the exe starts working correctly.
Looks like the exe is not truly independent of the uncompiled code?
Have any of you seen this? Is it a bug? Is there a fix?
thanks!!
I had this same issue and found some troubleshooting steps to fix the problem:
Change the version number in setup.py.
Change the name of the init.py (or whatever your first file is called.) Change the name in setup.py to match.
Copy your files into a separate folder along with the setup.py and rerun there.
I am working on a project in PyCharm that involves extensive computations, with long runtimes.
I would like to do the following: I come up with a version of my code; then run it, then I edit the code some more; however, the run I started before still only uses the old version of the code (i.e. the snapshot at the point of running).
Is this possible in PyCharm?
I run my project by selecting the Run 'projectname' option from the Run menu.
I understand the run works by pre-compling the .py files to .pyc files stored in the __pycache__ folder. However, I don't know the following.
Will saving the file in PyCharm cause the .pyc files to be replaced by new versions? This is something I want to avoid since I want one run to only use one snapshot of the source tree, not multiple versions at different points of execution.
What if some python class is only needed, say, 20 minutes after the run has started. Will the .pyc file be created at the beginning of the run, or on-demand (where the corresponding .py file might already have changed)?
I use PyCharm in my classes. My experience is that the all the required code, including the imported modules, are compiled at runtime. If you change anything in that suite you need to start running from scratch for it to take effect.
I'm not a professional programmer so my experience is with small apps. I'd love to hear form an expert.
EDIT: I found out that the error is that the resources couldn't be opened. Copying the directory into the folder where the .exe is didn't fix it. I tried removing the resources from the .spec file and the size of the .exe file is now 9 MB as opposed to 52 MB so I'm pretty sure the resources are included, but somehow they can't seem to be opened by the .exe. In case anything is wrong with it, This is my .spec file - I only modified the Tree thing to include the resources, the .exe filename and icon.
In other words, the question now is: Why can't the exe find my game resources, and what do I have to do to fix that? Also, I realised my resources folder has two subfolders - does that mean I have to go about writing the Tree differently?
I've made a game in Python (using Pygame, too) and want to make a single executable file so I can distribute it. PyInstaller seemed perfect for that, and eventually, after a while of searching, I found out how to get it working in this guide. After I tweaked my code to get step 2 working I created the .spec file, added the directory with the resources to it (as in step 5, and including the font file), copied it to the same folder the .spec file was in and finally I ran
build.py game.spec
and I found the .exe file exactly where it was supposed to be. However, when I open it, it just closes again after a few seconds, and I think it's just before the main menu shows up. I'm not really sure it's a font screw-up again though because I made sure to include it in the resources as well...
Unfortunately, searching for a solution on the web didn't help me at all, especially because half the links to the project are broken now.
If anyone knows what's gone wrong here (or needs more details) please let me know.
Details:
Python version: 2.7.7 32 bit
Pygame version: 1.9.3 32 bit
PyInstaller version: 1.5 32 bit
System: Windows 8.1 64 bit (the 32 bit programs have all worked fine so far though)
Try to open command prompt and drag exe into it and press enter, that way you will catch the error (if there is any) and then update your question, more info == more help.
I never used pyinstaller so I can't really help you on that.
Also I suggest you to try py2exe, it worked nicely with pygame (at least for me) and later you can make setup with NSIS or Inno.
Edit:
If the .exe can't permanently save the highscores (as you said in comment below) try running exe as admin, it might be just matter of write privileges , or maybe it is your antivirus who doesn't allow it to write (sandbox at Avast, unknown/rare file at Norton).
I didn't find out what the problem was but I did manage to get it working. I started by installing the newer version of PyInstaller (2.1) with pip and completing the same steps again, but this time in the Scripts directory and running pyi-makespec and pyi-build instead of makespec.py and build.py because that's how the new version works, I guess. At first it would still complain about the resources being missing unless I ran it from cmd, but I think that was actually because I forgot step 5 (Tree in the makespec file). For some reason now the .exe can't permanently save the highscores, but apart from that it's working perfectly.