How to change the source of python used by atom runner or script in Atom? - python-3.x

I want to run python code with Kivy by atom-runner or script, but when I run the simple any codes with Kivy, I got ModuleNotFoundError. I checked python path by
import sys
print(sys.prefix)
which prints ''/Library/Frameworks/Python.framework/Versions/3.7''
I guess I need to use Anaconda's python because I can run Kivy app on terminal and terminal uses python3.7 showing Anaconda.inc things.
But I can not find where to write path of python in Atom.
I tried pip install Kivy and it worked but nothing changed in Atom. And Kivy3 is in Application folder.
Just in case, my Kivy codes is this
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
class IntroKivy(App):
def build(self):
return Button(text="Hello, World!")
if __name__ == "__main__":
IntroKivy().run()
It will be perfect if I can run this codes without using terminal as it is faster and quick.
Best

Related

Python to EXE - PySide2 and Custom Modules

I'm trying to create an EXE from a Python project I built and I'm running into some issues. I've done this before with PyInstaller for simpler tools and cx-freeze for tools where I use custom modules but the way I used to set it up doesn't seem to be working anymore.
In this particular case I've tried:
cx-freeze==6.10
pyinstaller==4.10
py2exe==0.11.1.0
auto-py-to-exe==2.18.0
and a few others with no luck
Everything works perfectly fine through the Python 3.8 interpreter. I'm assuming it's either because of the way I'm importing PySide2 here (which I don't normally do but did for this project to see if it would speed up my programming time) or that the EXE modules can't find my custom modules. Here is a mock version of my program (names/paths changed for simplicity):
Example folder of my project ("C:\a\MyProjects\Project1"):
Example folder of the custom module I'm using. Each using various other built-in and/or 3rd party python modules. ("C:\a\path\to\external\modules"):
Example of my main file (C:\a\MyProjects\Project1\ui.py) I want to turn into an EXE:
import os
import sys
import colorsys
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *
import utils # module in project ("C:\a\MyProjects\Project1\utils.py")
sys.path.append(r"C:\a\path\to\external\modules") # custom module location for MyModule
from MyModule.foo import module1 as foo_mod1
from MyModule.foo import module2 as foo_mod2
from MyModule.bar import module1 as bar_mod1
from MyModule.bar import module2 as bar_mod2
from MyModule.baz import module1 as baz_mod1
from MyModule.baz import module2 as baz_mod2
class MainDialog(QDialog):
[...code...]
[...use of "dark.stylesheet"...]
[...use of "images\image 1.png"...]
[...use of "images\image 2.png"...]
def main():
global win
try: # try to close existing instances
win.close()
except NameError:
pass
win = MainDialog()
win.show()
if __name__ == "__main__":
app = QApplication.instance()
if not app:
app = QApplication(sys.argv)
main()
sys.exit(app.exec_())
Can someone tell me the best module and method to make this into a windowed (console-less), if possible, single file application. This is one of the more complicated tools I've had to make into a desktop app so if I can figure this out I should be good for most of the other things I have to do.
Thanks in advance.
EDIT:
Example of cx-freeze setup.py file in project I tried (C:\a\MyProjects\Project1\setup.py):
from cx_Freeze import setup, Executable
import sys
setup(
name="MyProject",
version="1.0",
options={'build_exe': {
'excludes': ["Tkinter"],
'includes': ["utils", "MyModule.foo", "MyModule.bar", "MyModule.baz"],
'path': sys.path + [r"C:\a\path\to\external\modules"],
'include_files': ["images\image 1.png", "images\image 2.png"],
'packages': ["PySide2.QtWidgets", "PySide2.QtCore", "PySide2.QtGui"]}},
executables=[Executable("ui.py", base="Win32GUI")]
Example of pyinstaller cmd command I tried:
cd C:\\a\MyProjects\Project1
pyinstaller -p "C:\a\path\to\external\modules" --onefile -w ui.py
# even tried this with a custom spec file like:
# pyinstaller --onefile -w ui.spec
There is a command in PyInstaller to include hidden modules call --hidden-module (You can use multile times). So, you can just do
pyinstaller -p "C:\a\path\to\external\modules" --onefile -w --hidden-module="example module 1" -hidden-module="example module 2" ui.py
This seems to have fixed itself after I got a new workstation and installed the latest Python (3.10) and Pyinstaller (5.1) versions.
Also think having your custom Python Libraries in the PYTHONPATH and/or PATH Environment variables may be important for allowing Pyinstaller to find them.

SDL2 module not found

I'm using python 3.7.9 and I have this code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
And I get this error:
Yes, I've tried reinstalling all kivy libraries multiple times, I've tried reinstalling Python but I still get this error.
My project settings:
My configurations:
I've even found it in 'External Libraries' folder:
I've tried to fix for literally 3 hours now and I'm too frustrated so I'm asking you guys. Thank you in advance.
First, forget pycharm, follow the kivy install instructions and see if you can run a kivy app via python from the command line. If you can't, debug this without the pycharm environments getting in the way.
If you can install and run kivy outside of pycharm, then your only problem is that you haven't installed it correctly within whatever python environment pycharm is using. I don't know how you configure it, but you'd need to make sure kivy and its dependencies are installed in that environment.

QsciScintilla on Pyqt4 for python35 error (unofficial whl)

I want to use pyqt4 on python35. However, the latest official release supports py=<34
So I found this university website https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
which unofficially extended support for later versions including python35
My problem is that QsciScintilla is not working. I tried to run this code:
import sys
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui, Qsci
from PyQt4.Qsci import QsciScintilla
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = QsciScintilla()
editor.show()
sys.exit(app.exec_())
The window becomes unresponsive then crashes:
Process finished with exit code -1073740771 (0xC000041D)
The reason I want to use pyqt4 on python3.5 is that I have a quit big application built on pyqt4
and I want to upgrade python version of the project to 35
I moved to PyQt5. It is always not a good idea to use an unofficial package.

ImportError: No module named tkinter. Mac OS Terminal

I have created a Tkinter window in a python script. The script runs perfectly in the python IDLE and generates the GUI. However, when I run this file outside of the IDLE by clicking on it on my Desktop, the terminal responds with ImportError: No module named tkinter. Even though tkinter is installed as its a default module when python is installed. Any help is much appreciated. Im working on python 3.7
Make sure your default python , the one that the terminal calls has tkinter installed.
So run 'python --version' in the terminal and if that yields 3.7 then your default python is 3.7.
Now try to import tkinter using that same python version.
open the terminal and run python then run import tkinter as tk
If that does not yield an error saying that the module was not found then most probably you are running the executable with the wrong permissions.

Unable to run Tkinter and Flask at the same time

I have the demo.py code where I let's say open the Web-Cam in tkinter window. Now, I also have flask code to display hello #localhost.
When I run the demo.py file it runs the function that I write first For ex:
import libraries
Flask code
Tkinter code
if __name__ == '__main__':
window.mainloop() #for tkinter This will run first
app.run() #for flask This will run when I close the Tkinter windows
How can I run both at the same time ?

Resources