I created a python script to control the RGB of my keyboard and my mouse and i want it to start when i turn my computer on. I have 2 solutions but i don't know which is the best.
the first solution is to build my script and run the executable on startup
the second solution is to run directly the python script with python.
the first solution is a little bit annoying because is i want to change the code, i need to rebuild my script. and also when i tried to run the exe (created with pyinstaller), it didn't work (because of the dlls i think)
the second solution is better if i want to change the code later, but i don't know how it would react if i run another python script (i don't even know if it's possible to run 2 python instances at the same time.)
so if you have any idea on which solution to choose, how to build a script using dlls with pyinstaller or if i can run multiple python instances (maybe i can run multiple venvs), feel free th help me.
PS: I tried to be clear but as i didn't speak english very well i don't know if you understood my issue.
Using windows : https://www.geeksforgeeks.org/autorun-a-python-script-on-windows-startup/
Using Linux : follow this https://stackoverflow.com/questions/24518522/run-python-script-at-startup-in-ubuntu#:~:text=Put%20the%20command%20python%20startuptest,and%20put%20the%20command%20there
Related
1- i want someone to help with this part
https://automatetheboringstuff.com/appendixb/
about Running Python Scripts Outside of IDLE and sending command line args .
2- i converted my code to .exe by pyinstaller ; what's the difference between this and running it
as a script .
3-how scripts are done . i see experienced people says :"i made a script to do something for me " how is that done >?
*i'm a beginner so try to make answers simple as possible.
If you're wondering about command line arguments, look into the "argparse" library https://docs.python.org/3/library/argparse.html.
The difference in the .exe and the normal script is that that the .exe versions (conventionally) are able to be redistributed to other sytems that don't have python installed whilst still being able to run the script. If you're only making the script for yourself the only real benefit is that you dont have to enter your IDE (code editor) every time you want to run the code, however if it's still in development then you'd have to compile the code every time you made a modification if you're wanting to run the code as an executable, which is very impractical.
Your third part is very, very vague. Python can be very versatile and i recommend you continue looking at the automatetheboringstuff.com website if you're interested in making scripts that can complete repetitive activities (although i must strongly advise you against using scripts maliciously).
I'd like to iteratively write and test my python code in the Python console. I can't find a way to easily load what i've got written in the editor (somefile.py) into the Python console in Pycharm. Is there a trick to doing so?
Pycharm will let me run the entire script but that's not useful because i want to build up my state in the shell by experimenting with the functions and data i've got in the environment (kind of like how a lisp programmer would use a REPL).
Pycharm have this alt-shift-E option.
This way you can write in the editor, select the lines you want to run and run them by alt-shift-E.
I use it all the time, although I find a lot of people not fameliar with this option.
to give a bit of background I'm trying to use TensorFlow object detection api. I have been following this tutorial https://www.youtube.com/watch?v=MoMjIwGSFVQ
15 minutes into it he uses Spyder, and runs the python files on it. I've never used Spyder before, and for some reason it's not running my files at all? When I press run nothing is returned on the console.
So can anyone suggest a different IDE that I could use that would allow me to do the same things as he does? Or would anyone be able to tell me why Spyder might not be running. (I installed it in Linux terminal, and simply imported the file as a project as he did, and so I'm a bit stumped as to whats going wrong).
Thanks!
There was a simple task - well, in Python it took around one hundred lines of code (the task was only to ask users for input files, process them and write results on disk). But the requirement was that it must be executable on PCs without Python interpreter. I used py2exe to make an executable file (it has increased the size from 3Kb to ~12 Mb but doesn't really matter).
The problem is - when one tries to run this *.exe, it shows black command line window for half a minute and only after that - file-selecting dialogue. Is there a possibility to get rid of that half-minute delay? Of maybe there are other .py to .exe converters which would suit better in this situation?
In py2exe
console = ['yourscript.py']
will generate a command window, use the following instead
windows = ['yourscript.py']
http://www.py2exe.org/index.cgi/ListOfOptions
This is perfectly normal when making exe files with Python code. When you make an executable file, Python itself is bundled into the .exe. This is so the user does not have to install Python on their machine to make it work. Python is an interpreted language and requires the interpreter to be bundled.
You could always try using alternatives to see if the compression rate is smaller, but chances are, its not a big deal.
If it is the code that is taking a long time, you may consider posting your code on Stack Exchanges' Code Review to see if there is anything that could be improved.
Further, if you are using Python 2.7, you should consider checking out PyInstaller. It is surprisingly easy, however, it has a couple of problems - especially with the PySide Framework - works great for plain PyQt though.
pyinstaller myscript.py --name="MyApp" --onefile
However, for a full list of optional parameters you should really check out the documentation.
I created an executeable of my Python script. Everything works just fine on my first computer but when I try to run this very same executeable in another computer, it wont work. When I try to run my executeable I see that computer tries to open it, because command prompt window appears but nothing else happens, prompt window will disappear. Problem can't be in computer, because both my computers are 32 bit Windows machines and I have done similar things before but this kind of error I see first time.
I don't want to post my code at first, because it is more than 500 lines long. But I will give some more specifications about my problem.
This program I create is actually advanced version of application i made earlier. And earlier version worked fine in both of my computers. This advanced version, I am working on now, is developed into many standalone Python scripts unlike first one which was only one script. Could this be the source of my problem? Should I do something different when running setup.py now when I have many scripts?
And then there is third version of my application. Executeable of it runs fine on computer where I created it, but in my second computer it wont run either. But this time I get error too. When I run this program in my second computer the opening screen of aplication appears, there are some buttons which are meant to open other scripts, when they are clicked on. But when I click them I get following error: The system cannot find the path specified.
If someone is willing to look into my long code, then I am willing to share it. But again I dont want to post it here.
I am using Python 2.7 and windows 7 in my first computer and windows XP on my second computer.
I would be very grateful if someone points me right direction which helps me to solve my problem.