Why is my python installation not working properly? - python

http://pastebin.com/BJiXC022
At first my python is working just fine with tkinter. When I change the working directory, it somehow stops working then. It even manages to refer the tkinter.py file in that directory even when I never even typed the name of the file there. I just wanted to import tkinter. My tkinter.py file is also not working even though it is almost exactly the same as the first 10 lines. How do I fix this problem? I reinstalled os and python yesterday, I am running OS X 10.10.3 and the newest Python 3.4.3. Here's tkinter.py:
http://pastebin.com/VBHqFGLZ

You have a file named tkinter.py in /Users/nikolas/Documents/Python/tkinter.py. Changing to that directory and importing tkinter will import the local file, not the one from your Python installation. You see the error because your tkinter.py file does not provide Tk.
The solution is to rename your file to something other than tkinter.py.

Related

Python Pyinstaller build fails using win32com package [duplicate]

I am trying to convert my .py file to an .exe file and I have tried all methods (auto-py-to-exe, pyinstaller, cz_freeze) and it does create the exe file but it always gives an error or the window opens and closes as soon as I double click the file.
It is a SpeechRecognition AI project coded in python. And it works just fine in the IDLE but once I create the .exe and try to run it the window pops up and shut down immediately after. (I use the cx_freeze and setup.py method for this)
If I try to convert .py to .exe using pyinstaller it gives me several different kinds of error messages.
As a .py file it works just fine but it doesn't work as an exe.
This is the error I get when using pyinstaller or auto-py-to-exe: Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception: Module 'pythoncom' isn't in frozen sys.path
Module 'pythoncom' isn't in frozen sys.path
I tried several things but nothing seems to work. I was previously using Python3.10 so I uninstalled it and downgraded to Python3.8 and reinstalled all the modules so technically it should work. I tried to create .exe files of another project and it worked just fine.
Another issue I come across is ModuleNotFoundError: No module named 'pyttsx3.drivers' I compiled the .exe using cx_freeze and it did create an .exe but it gives me this error.
Could someone please help me out with this?
(PS: This is the list of imports I am using for this project:
screenshot of all imports
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import wikipediaapi
import webbrowser
import os
import time
import subprocess
import wolframalpha
import json
import requests
from newsapi import NewsApiClient)
I just solved this for my project, which is using none of the direct imports your project is, but it appears the same low level library is causing an issue.
In my case, the single import is:
from pywinauto.application import Application
The solution is to tell PyInstaller to bundle the missing .DLL, which in this case is pythoncomxx.dll where xx is your python version. 39 in my case.
Here is the call that eventually worked for me.
pyinstaller --onefile --add-binary ".venv/Lib/site-packages/pywin32_system32/pythoncom39.dll;." autoTest.py
More generally: pyinstaller --onefile --add-binary "[path to dll];." file.py
Note, I'm on Windows. If you are on mac/linux, the ; character in the --add-binary argument would be :. See note in the documentation here
Discussion
This clicked for me when I used ProcMon to profile the file access of my initial version that was failing. It was looking for this .DLL in a bunch of different folders, then quitting.
The answers to this question were helpful. But I didn't want to settle for copying the DLL to output manually. And consequently, having to use a directory output versus a single executable file.
Answers on this question also gave the hint about using the --add-binary flag, but ultimately I had to provide the specific path to the missing DLL instead of just referencing by name as these answers showed. It probably works to specify the DLL by name if it is accessible on your PATH.
How to locate this DLL in the first place? Do a search on your site-packages folder.

python application won't start after changing the manifest name

I created a python application and used PyInstaller to convert it into .exe.
My problem is: I was playing around with the .exe files for practicing, And i changed the manifest name and the application doesn't work (indeed) but the wired thing is: when I re-named that manifest file to the original name. The application is still not working with the same error: '380 Ordinal not found'. And I also tried to uninstall the application and re-install it, but again still not working (BUT if I install it with a different name OR path the application will work fine).
I think it is something related to Temp files some of the settings are stored somewhere and in order to let my application work I need to clear these files (Am guessing).
So please could someone explain to me the cause of the problem and why it happened and how to resolve it?
Python 3.7,
Pyinstaller 4.5,
win 10
I found the solution: the problem happened because the manifest becomes tattooed into that executable name after the launch.
So modifying the modification date of the exe file will do the job and the application will works fine again.
Here is a python script that can fix this kind of problem:
import os
import time
import datetime
path = './/run_application//run_application.exe'
modified_ts = time.mktime(datetime.datetime.now().timetuple())
os.utime(path, (modified_ts, modified_ts))
print("Executable modification time has been updated.")
Here you can see the topic with more explanation https://github.com/pyinstaller/pyinstaller/issues/6223

pyinstaller importerror when module is in the same directory

Pyinstaller recently stopped importing a module that it previously had no problem with so I set up a simple test case to isolate the problem.
I created a script (pt.py) as follows:
import py_script1
import py_script
print('hello world')
py_script.py and py_script1.py are identical and located in the same directory as pt.py. They both import os, random and math and have some functions in them.
When running pyinstaller with default settings it compiles the .exe file but when I try to run it, I get "ImportError: No module named py_script". Checking the warnings text file shows that it was never compiled into the .exe file.
Changing the order of the imports doesn't help - I get the same error. I have also tried to uninstall and reinstall pyinstaller but that has not helped
How is this even possible - the two imported scripts are identical and are located in the same place!
More importantly how do I fix this problem?
PyInstaller 3.3.1
Python 3.3.5
Windows 10
I solved it. Despite the misleading exception description I isolated the problem as the following line in the imported file:
SB_CONSTANT = 0.00000005670373 #Stefan–Boltzmann constant (W/m2/K4)
For some reason this number broke pyinstaller. I changed it to:
SB_CONSTANT = 5.6704e-8
...and the module imported fine.

CX_Freeze exe references old pyc file?

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.

Py2Exe won't successfully compile the pygame.font module on Python 3

I made a program using the pygame module on Python 3 and it works fine within python, but when I try to compile is using py2exe it won't run. (I just get the programName.exe has stopped working error upon trying to run it).
I managed to narrow down this problem to the pygame.font module as when I comment all the lines that use that module everything works fine. I tried to forcefully include the module using the -i flag in py2exe, but it doesn't appear to change anything...
What am I doing terribly wrong?
Edit: I managed to get the reason of the program not working - it crashes as it can not find build\executable.exe\pygame\freesansbold.ttf . What I don't understand is why the hell is the pygame folder supposed to be located in a folder with the name of my executable? (Of course, I can not create a folder with the same name as an existing file in the directory). If anyone has a clue to how to fix it, please help!!
I had the same problem using cx_Freeze, so hopefully this will work for you as well. Open up your pygame package folder. It should be C:\Python34\Lib\site-packages\pygame. There should be a True Type Font File titled freesansbold.ttf. Copy that file then open the folder containing your exe program. There should be a zipped file called library. Open it up and go to the pygame folder inside the zipped file. Should look something like this \build\exe.win32-3.4\library.zip\pygame. And just paste the freesansbold.ttf file in that folder and it should work perfectly.
I managed to find a way! By including -l library.zip argument in the build_exe command and then following the instructions given by DeliriousSyntax in the answer above I managed to get it to work!

Categories