Opening Python IDE on Desktop - python

I am trying to open the python IDE with a specific program open on my desktop (in the shell so that I can edit it). The code I am using is:
os.system("C:\Python27\lib\idlelib\idle.py C:/Python27/lib/file_name.py")
Its working, but its opening three things:
A command line (without the actual command line)
An empty IDE
The program I was trying to open
I dont want the previous two things to open, just the third. Whats going on, how do I fix it?
Thanks,
Neil

The command window opening is an inherent part of os.system, something as simple as this should work:
C:\Python26\Lib\idlelib\idle.py "C:\file1.py"
This opens just the code you want in IDLE, without the shell. To run it in the IDLE shell (opening it in the process), simply press F5.

You can use pythonw.exe for this:
os.system('C:\Python27\pythonw.exe "<absolute path to your file here>"')

Related

Python IDLE 3.9.1 file not opening in windows

I had saved a python file after working on it for sometime, but now when I open it, Python 3.9.1 opens a window then immediately closes. I had done lots of work on this and don't want it to go to waste. I'm on Windows 10.
If you’re using the Open option when you right-click or you are simply double-clicking the script, the program will run and close so fast you won’t even see it.
Here are two options I use:
Open up the Command Prompt. You can easily do this by going to the address bar of your File Explorer and enter ‘cmd’. If you’re in the directory where your script is, the current working directory of the Command Prompt will be set to that. From there, run python my_script.py.
Edit your script with IDLE. If you’re using an IDE, it should be nearly the same process, but I don’t use one so I wouldn’t know. From the editor, there should be a method for running the program. In IDLE, you can just using Ctrl + F5.
Right click on it and clicken "open with". Then choose Python IDLE.
You are trying to run the file instead of editing it.
You have to right-click the file and you should the "edit with idle" option.

python 3.6.2 not giving me option to create or run files or anything of the sort

I know some basics of Java and C++, and am looking to learn Python
I am trying to develop some random stuffs to get a good feel of how it works, but i can only make 1 line scripts that run every time i press enter to go to the next line.
I've seen tutorial videos where they can just open up files from a menu and type away until they eventually run the program.
I'm using IDLE, and i don't see options to open up new stuffs; I can only make one or two line programs. When i tried to make a calculator program, i didnt know how to run it because it ran every line of code i typed in unless there were ...'s under the >>>'s.
I think it's because i am in interactive mode, whatever that is.
How do i turn it off, if that's the problem?
There are many different options for writing python scripts. The simplest to use is Idle, it come with the Python download. Within Idle, create a new document to write a script. Once finished, save it as a .py file, and you can run it within Idle. For my personal setup, I use the text editor Atom. I can create documents easily, and run them through the terminal on my computer. Hope this helps.
To exit out of the "interactive mode" that you mentioned (the included REPL shell in IDLE) and write a script, you will have to create a new file by either selecting the option from the top navigation bar or pressing Control-N. As for running the file, there's also that option on the navigation bar; alternatively, you can press F5 to run the program.

Cannot run a Python file from cmd line

I have installed Python and written a program in Notepad++.
Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.
I cant run the file at all, how can run this file?
Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.
I assume you are running the script with command python file_name.py.
You can prevent closing of the cmd by getting a character from user.
use raw_input() function to get a character (which probably could be an enter).
It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.
You have a number of alternatives:
First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.
Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.
As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.
As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.
Try to open in Command Prompt instead of run window. The syntax is:
py filename.py
If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you

Run in OPEN Python-Idle from Notepad++

Im using a shortcut in Notepad++ to Run my Python-files directly in Python IDLE.
From the shorcut.xml, you can see how I'm using it:
<Command name="runinpython" Ctrl="no" Alt="yes" Shift="yes" Key="81">"C:\Python27\Lib\idlelib\idle.pyw" -r "$(FULL_CURRENT_PATH)"</Command>
The problem is: Every time I press Shift+Alt+Q, it opens another IDLE-Window and I'd like to only open it once and then run my .py-files in it, otherwise I have to close the IDLE windows each time after every execution.
Do you know a way to do this?
Thanks
http://mpcabd.xyz/notepad-plugin-to-run-python-scripts/ supports it
-> when running py-scripts from within Notepad++, there won't be new console-windows opened all the time, but instead the script always runs in the open cmd-window :-)

Python shell window in compiled applet

I am trying to make an executable python program on MAC OSX. I used the build applet program and it runs, but I had some data printing in the shell window and the executable file does not open a window. Is there a way to open a shell window with an executable python program?
Thanks
Not sure about generating another shell window, but do you need to have an entire shell open? What about getting the information to the user in a different way, such as:
use another Toplevel window and insert the output into a Text or Listbox, rather than simply printing it. This could also make it easier for users to copy the output (if that's something they might find useful).
write out a data/log file.
If you are using Automator to simply run your python script, and you really need it to open a shell window, here is a cheap hack:
Using a simple application with Run Shell Script action:
open -a Terminal /path/to/python/script.py
But if all your application is doing is printing output, all that output would be visible in the Console.app.

Categories