Pyinstaller Exception: Cannot find PyQt4 plugin directories - python

I will spare unnecessary details here and try to keep it short.
My issue: I built my program using the following in command prompt
pyinstaller --onefile --icon=logo.ico H:\<script location>
Originally, this compiled and output perfectly fine. I opened up the exe to test it, and it worked like a charm. However, I noticed a small typo of mine and adjusted my script to fix it. When I went to use the same command prompt line to build the .exe again is when it gave me the PyQt4 error. This actually happened earlier today as well, to which I solved it my uninstalling both PyInstaller and PyQt4, restarted my computer, then re-installed them. Everything else I tried just did not work.
I do not understand how it would work at one moment and then, literally not even 30 seconds later, it gives me this exception. I would prefer not to constantly uninstall and then re-install PyQt4 and PyInstaller in order to build my .exe files.
I am running python 3.5 through idle if that makes any difference here.
I do not have any other form of python installed either.
I have been downloading my packages using pip and from the wheels located at http://www.lfd.uci.edu/~gohlke/pythonlibs/ if that also makes a difference.
I saw the solution here Exception: Cannot find PyQt5 plugin directories when using Pyinstaller despite PyQt5 not even being used . However, I do not have Anaconda installed that could be interfering like this guy found.
Any help is appreciated!

Related

pip installs package to AppData despite admin privileges

The title of the question kind of says it all, but here goes.
I'm currently trying to install pyqt5 and pyqt5-tools on my system (not in venv). I have a Python 3.9 installation in C:\Program Files\Python39. Usually everything works fine in that, if i have admin privileges pip installs the package to the Python installation and if not it puts it into C:\users\username\appdata\roaming\python\python39. Now I have encountered something strange, even if I have admin privileges and try to install pyqt5 it decides to put it into the AppData Python directory instead of the actual python install inside C:\ProgramFiles\Python39.
I know that I could probably fix this by using -t, but I am curious as to why it would be this way. Why only PyQt5? Every other package worked absolutely fine until now. I've tried installing random other packages afterwards and they also worked fine. Even PyQt6 was completely normal. So what is it about PyQt5 that makes pip act in weird ways? After about 15 retries and permutations of the install I am still no closer to an answer.
I'm grateful for any explanation at this point, so thank you in advance!

Import packages works in idle.exe but not in IDE (python)

Please note that I am a complete beginner and installed python simply by going to the website and clicking "install". It used to work fine.
Now suddenly I have this frustrating situation where I can run just about anything in the idle.exe found in the scripts section of arcgispro, but cannot run the same .py file in an IDE. As a beginner this is obviously a headache as I would like auto code formatting, suggestions, etc. Literally any IDE would be fine (spyder, pycharm). The problem is that every single time there is some kind of error with the package imports. e.g. from pycharm:
import shapefile ModuleNotFoundError: No module named 'shapefile'
It's not just shapefile... this is happened at random times with numpy and also matplotlib.
When I look at "Installed Apps" on windows, it just says Python 3.10.0 and Python Launcher.
No, there is no file that I created called "shapefile.py"
A lot of solutions suggest things with pip... I have absolutely no idea what pip is...is it installed program? where do I find that?
EDIT: I just found out that the system paths of the two are different so this explains why one works but the other doesn't... but how can I make it so that the IDE would work?
Ok, simple answer:
In Pycharm, go to the bottom and click on Python Console. Then type pip install pyshp. Voila! Assuming it works for other packages as well. Still do not know where to make pycharm work with the other environment...

Compiling Python File for Distribution

I have a really simple Python script. It’s written in a single file however I did have to install two things using pip. I’ve created this on Mac and I need to somehow compile it into a runnable application on windows. I’ve spent hours trying to use pyinstaller to make it into an exe file but I don’t think the dependencies are included in that ... I’ve also tried creating a virtual environment using venv but that doesn’t work either. I first tried using pyinstaller on Mac which was really easy but didn’t run at all when transferred it to windows. I then have been trying to do it on windows but it’s just very difficult and it’s just one error after another. I finally managed to build the app on windows using pyinstaller but it said “failed to execute script ...”
So does anyone know any simple way to make it into a runnable application? Doesn’t have to be an exe.
Thanks in advance.
Have you tried using py2app. To install it, type: pip install py2app.
Check out This link for more information.

PyCharm error - No module named 'sip' (PyQt4)

OK, so I need to make a project in PyQt, and I'm using PyQt4 since I found more tutorials on this and it is easier for me.
I installed PyCharm as my IDE. I haven't had any python compilers so I installed Python 3.7.5 (from Microsoft Store since PyCharm recommended that), and configured the interpreter in PyCharm (so now, python works)
Then, I needed to install PyQt4, and since it didn't work from PyCharm's project interpreter -> install package, I downloaded "PyQt4-4.11.4-cp37-cp37m-win_amd64" and installed it with pip.
Then, I installed sip also with pip.
The thing is that I get an error in my code in PyCharm.
from PyQt4 import QtGui
ModuleNotFoundError: No module named 'sip'
I also configured all my Windows PATHs, when I installed sip it gave me an error saying that the path isn't added. I added that path.
I also added the pyqt4 path.
These are my paths:
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\sipbuild
C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages
'C:\Users\b997a\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
And these are all the packages I think I have installed in PyCharm:
Do you know what I can do? I really don't want to use PyQt5 since I know a found tutorials on exactly what I want to do on PyQt4 and I don't really have time to learn PyQt5 now...
I also tried to see if Python 3.7.5 Shell (IDLE) will raise an error, and yes, it did. I have the same error in Python's IDLE.
What is the problem? It worked for a while until I deleted Python a few weeks ago, but now it doesn't work anymore.
Thanks a lot!
I have recently faced such issues, so my recommendations are:
It's good to activate your virtual env for your project.
Usually pip should install the required binaries, but if it doesn't, try searching the same from pycharm -> settings and add directly from there. This has always worked for me.
P.S. I was not able to add comment, so I posted it as answer.

Installing cx_freeze via msys2

I am trying to write a small gtk application with Python.
I was told that you should use msys2 for MS-Windows. See related question: Setting up developement environment: PyCharm, python-gtk, windows
Now I need cx_freeze. There are wheel-files for windows, but I guess the msys2 environment is different, and that's why installing "cx_freeze" fails (no gcc around).
See files of cx_freeze: https://pypi.org/project/cx_Freeze/#files
Now I am unsure if I am on the right track.
Is there a way to use the ready build wheels from a python which is started in msys2 (In my case C:\msys32\usr\bin\python3.exe)
Installing cx_freeze worked after installing gcc. But now I get this error:
cx_Freeze.freezer.ConfigError: no base named Console
I guess I should not compile cx_freeze and get my environment use the provided wheels.
Update
I leave this question open, because someone else could find a solution and help someone else again. But I switched from gtk to pyside2 (QT). Everything is much easier now.

Categories