I am in python31,
then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31
The moment it opens the notepad, it starts python26
I thought it has something to open with, and I have changed that to python31
And it still opens python26
EDIT:
The file is created by python26, but it is not executable.
I am guessing here, the question it not very clear.
It sounds like the .py extension in Windows is associated with the Python 2.6 runtime. (This normally get setup this way during installation of Python on Windows). You can change this by updating the associated file extensions and programs in Windows.
By double clicking on the file it is not opening the file for editing but instead running it. If you want to edit the file you have to either right-click and select an approriate edit action or open the file from your editor's 'open file' action. (Or change the .py extension to open in your favourite editor)
I had similar problems, and right clicking and changing edit options didn't solve it. You can try repairing python31 installation with running the msi installer and selecting it as the default python
Related
I've looked through many similar questions, but no one seems to have had this same problem. I can open the IDLE shell perfectly fine from the start menu. Once in, I can use File->Open to open any .py file.
However, my problem is that if I try to open any .py file from File Explorer with IDLE, the files will run, but the IDLE application won't come up. This especially makes it difficult to quit running when I can't even close the application if it's not open. It also makes it very tedious if I have to always use File->Open from the IDLE shell if I want to open a .py file. How can I at least get the Edit with IDLE option to come back?
I had this same issue and came looking for an answer, but ended up figuring it out:
I had the issue when I downloaded the 64-bit version for windows (3.9.7), but the issue was resolved when I instead installed the 32-bit version of 3.9.7.
Now I can right-click > "Edit with IDLE"
When you open the file from within IDLE, you open it in an edit window. If you try to open it from the file explorer, it will RUN it on IDLE. So that's why you can't just "open it" from the explorer.
I suggest that you start using some other tools to code in python. Sublime Text and Atom are great text editors, and both can be used as a python IDE.
The issue could be outside of Idle as I had the same behavior on OS 12.6. Restarting the Finder from the Force Quit menu resolved.
I installed Spyder using Anaconda, and I am able to launch the IDE using the Spyder icon in my start menu (Win10). I wanted to set my preferences to open all .py files with Spyder, so I followed the Spyder start menu button to an executable, pythonw.exe. The problem is that I cannot launch pythonw.exe by clicking it.
How does the start menu icon for Spyder, which points to pythonw.exe, launch Spyder, but clicking the executable does not yield the same results? Also, when I double click spyder.exe in Anaconda\Scripts a command prompt opens along with the IDE, which does not happen when I click the start menu icon.
Why does this application behave so much differently than any other application I've used before (if this is just how things are in python, I apologize as I'm new!) and is it possible to set Spyder as the default application to open .py files in the same way I can open source files with IDEs in other languages?
Cheers
I found the answer in this question, answer by xyzjayne.
You create a bat file with the following contents:
start YOURPATH\Anaconda2\pythonw.exe YOURPATH\Anaconda2\cwp.py YOURPATH\Anaconda2 "YOURPATH/Anaconda2/pythonw.exe" "YOURPATH/Anaconda2/Scripts/spyder-script.py" %1
YOURPATH will be the path leading to the folder just above the Anaconda folder. For me it was:
C:\ProgramData
And you select the Choose default program to open this file... - and you choose that bat file.
When you go to Spyder shortcut's properties, the target includes a few files. So my guess is that for Spyder to run, all of these files must be run, and that's why when you just point .py files to one exe it doesn't work.
You can right click any of your *.py file, go to properties and choose Spyder as "Opens with" choice.
Right click on your file, and select open with or Choose default program to open this file.. and then in your system... select .. \Anaconda3\Scripts\spyder.exe .
I have also provided you the screenshot of the above path in my system for your reference.
In Windows 10 Anaconda installs itself into a hidden folder called ".anaconda" which is placed in the Users directory under your own profile sub directory.
When you first try to use the right-click menue "Open with" it opens up in C:\Program Files so you have to go up one folder and down into Users. You may need to have previously set one of the options in the View Menu of the file manager so that you can see hidden files. You can't do this from the "right-click open with" place, you have to set that in the regular file manager.
You will find a file called Spyder.bat a couple of folders down within that, e.g. C:\Users\Your_profile.anaconda\navigator\scripts
It will take forever to open each time.
for Anaconda3 on win11:
start YOURPATH\Anaconda3\pythonw.exe YOURPATH\Anaconda3\cwp.py YOURPATH\Anaconda3\ "YOURPATH\Anaconda3\pythonw.exe" "YOURPATH\Anaconda3\Scripts\spyder-script.py" %1
Below a baby-step guide to make Spyder your default program to open .py, including an icon!
First, search for Spyder in windows, and open the folder that contains spyder. Spyder will be a short-cut file. Right-click the spyder shortcut file and choose "Properties". Copy all the contents of the "target" content.
Open a Notepad. Write the word start and the paste the contents you obtained in step 1. Now, save the file as .bat, with any name you want, let's say "myspyderlauncher.bat", in a convenient location for you.
Go to any .py file, and choose "open with", and look for your .bat file (following the example above, the "myspyderlauncher.bat" file). Choose "always" to always open .py files with your bat.
Now double click the .py file and Spyder will automatically be started. VoilĂ !
Did you say you want a nice spyder icon too instead of that ugly white icon? Here are the next steps (optional):
Download Bat to exe converter (not worries, you will not need to install the software): https://web.archive.org/web/20190304134631/http://www.f2ko.de/en/b2e.php
Unzip the Bat_To_Exe_Converter.zip and go to the "portable" folder and run the .exe file. Open your .bat file ("myspyderlauncher.bat" in the example above), and then go to the right menu, click and look in the "icon" option and look for the Spyder icon (.ico file), which is normally in ...\Anaconda#\Scripts.
Now press "convert" in Bat_to_Exe and save your new .exe file in a convenient location with a convenient name you want. (Let's say we call it "spyderlauncher.exe")
Go to any .py file, and choose "open with", and look now for your .exe file (following the example above, the "spyderlauncher.exe" file). Choose always to always open .py files with your bat.
You will see that all your .py files are now associated to spyder, with a beautiful icon attached, and opening in Spyder.
Some screenshots below
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am on Windows 7. I have Python 2.7.8 (64 bit) installed. Today, I changed the default program that opens .py files from IDLE to Windows Command Processor and stupidly selected the checkbox that said "always use the selected program to open this kind of file".
What I want to do is change my default program back to IDLE.
When I attempt to change it back to IDLE, I go to Control Panel\Programs\Default Programs\Set Associations and select the .py name and click Change Program. I do see python.exe but selecting that does nothing. I then use the "Browse" button to navigate to C:\Python27\Lib\idlelib but don't know if I should select idle.py, idle.pyw, idle.bat or some other IDLE program that will force the default program to be IDLE!
Nothing happens after I select one of these.
How do I make IDLE be the default program that opens .py files and now disassociate Windows Command Processor from being the default?
If the "always use the selected program to open this kind of file" checkbox is grayed out, ungray it by:
Open regedit Go to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
Find the .py extension among the list
Delete the UserChoice key (folder)
Then you can navigate to:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python XX and choose IDLE...
or
navigate to C:\...\PythonXX\Lib\idlelib\idle.bat and select that.
---- If You are updating from a previous version of Python ----
I just updated from Python 3.4 to Python 3.5 and it was a nightmare setting IDLE as my default program. I wasted so much time. I finally got it to where I no-longer have to right-click and select IDLE. Instead, I just click on a .py file and it opens IDLE by default... and it has a legit-looking Python icon (not an ugly .bat icon).
I'm posting this so mainly I'll remember how I did this!
Uninstalled Python 3.4 using control panel (Windows).
Deleted remaining C:\Python34 folder entirely.
Went into registry:
Windows "start" orb (bottom-left) > type "run" > type "regedit" in Run dialog box.
Looked in the following areas and deleted python keys entirely:
HKEY_CURRENT_USER\Software
HKEY_LOCAL_MACHINE\SOFTWARE
HKEY_USERS.DEFAULT\Software
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
(Optional, do with caution) In left pane of Registry Editor, right-click and select "Find". I looked in keys, values and data but looking in just keys might be enough. I deleted the ones that looked very specific to start-up procedures. You can press F3 to find again each time.
I ran CCleaner specifically to remove / clean-up the registry, but also to clean up temp folders and just general maintenance. Run it several times.
Restart computer
Install new version of Python. If installation fails first time, consider un-checking some of the "Advanced Options" during installation. Ex: "download debug binaries".
After you install, .py files may not be associated to a program. You can go to your control panel and set file associations.
Look for .py file extension and click "Change program" button in the top-right. Browse to the location of idle.bat. Example: C:\Python35\Lib\idlelib. Click the idle.bat file and press OK.
At this point, you should be able to click a python file (file with .py extension) and it will open using IDLE's idle.bat program. I've read that sometimes this doesn't work for some people.
But now, the icon of .py files look like the icon of the .bat program. This looks like crap so I did the next steps to associate a Python icon with .py files.
Start > run > regedit (to launch Registry Editor)
In Registry Editor, navigate to: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice and make note of the Progid (Applications\idle.bat in my example).
If UserChoice is not there, navigate to HKEY_CLASSES_ROOT\.py and make note of the (Default) value (ex: py_auto_file).
I didn't know which to change so I changed BOTH.
Go to: HKEY_CLASSES_ROOT\Applications\idle.bat. A "DefaultIcon" folder didn't exist so I right-clicked idle.bat and chose New > Key and named it "DefaultIcon". For the (Default) data, I put C:\Python35\Lib\idlelib\Icons\idle.ico to reference the .ico image that's within the IDLE icons folder.
Go to: HKEY_CLASSES_ROOT\py_auto_file and did the exact same steps as step 12.1.
Restart your computer.
End-result
After all these steps, I am now able to double-click a .py file in Windows and it launches the file in Python IDLE.
Right click on any .py file
Click Open With...
Click Choose a default program...
IfIDLEis on the list, click it.
else
Click Browse, and find the IDLE program
Click OK and voila!
I recently re-installed Python 2.7.3 from python.org on OSX 10.8.2, and now nothing (literally nothing I can see) happens when I double-click on .py files in Finder, or when I right-click/Open-With/IDLE(2.7.3). (Edit: IDLE is already set as the default program to open .py files; the "right-click" part was just to illustrate I couldn't open them either way.)
I have Tcl/Tk 8.5.13 installed (re-installed after I re-installed Python), and I can open IDLE itself just fine, so this isn't that issue where IDLE won't work without the right version of Tcl/Tk. I can also open .py files from the Terminal using idle -e file.py without a problem.
I did notice that the Python Launcher activates when I open files this way, and is absent when I double-click on .py files in Finder (although again, literally nothing happens when I do this--I have the IDLE icon in my dock and it doesn't start bouncing or anything). Could this be a Python Launcher problem? If not, does anyone know what's going on here?
Update: I tried opening IDLE first and then double-clicking on .py files, and that works. So it seems it's just an issue of IDLE not being opened when you try to open a .py file in the Finder.
I know that means I now have at least three other ways of opening my .py files in IDLE, but I really like just being able to navigate to a file in Finder and open it when IDLE itself is not yet open. So I'd still really like to solve this problem if possible (also I really hate when stuff that's just supposed to work doesn't).
Update: Per Ned Deily's suggestion I checked for errors using Console.app and found:
3/8/13 10:42:38.006 AM com.apple.launchd.peruser.501[276]: ([0x0-0x199199].org.python.IDLE[1975]) Exited with code: 1
pops up whenever I try to double-click a .py file in Finder.
Make sure you have set the intended instance of IDLE as the default application for all .py files. One way to do so is to select a .py file in a Finder window, then select the Finder -> File -> Get Info menu item (or Cmd-I). In the Open with: section, pull down the application menu item and select the desired IDLE; if you have multiple copies of IDLE installed, select the Other.. menu item at the bottom of the list and use the file chooser to select the right version of IDLE. Then, click the Change all... button to Use this application to open all documents like this one. You should now be able to launch a .py file in the desired IDLE by double-clicking. If this doesn't work, examine system.log to see if there are any error messages being logged. You can use the Console utility to examine logs (/Applications/Utilities/Console.app).
Does anyone know where or how to set the default path/directory on saving python scripts prior to running?
On a Mac it wants to save them in the top level ~/Documents directory. I would like to specify a real location. Any ideas?
On OS X, if you launch IDLE.app (by double-clicking or using open(1), for example), the default directory is hardwired to ~/Documents. If you want to change the default permanently, you'll need to edit the file idlemain.py within the IDLE.app application bundle; depending on which Python(s) you have installed, it will likely be in one of:
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPython 2.x/IDLE.app/Contents/Resources
/Applications/MacPorts/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 2.x/IDLE.app/Contents/Resources
/Applications/Python 3.x/IDLE.app/Contents/Resources
Edit the line:
os.chdir(os.path.expanduser('~/Documents'))
On the other hand, if you start IDLE from the command line, for example, with:
$ cd /some/directory
$ /usr/local/bin/idle
IDLE will use that current directory as the default.
I actually just discovered the easiest answer, if you use the shortcut link labeled "IDLE (Python GUI)". This is in Windows Vista, so I don't know if it'll work in other OS's.
1) Right-click "Properties".
2) Select "Shortcut" tab.
3) In "Start In", write file path (e.g. "C:\Users...").
Let me know if this works!
In Windows 10+, click the Windows Start button, then type idle, and then right-click on the IDLE desktop app and open the file location. This should bring you to the Start Menu shortcuts for Python, and you'll find a shortcut to IDLE there. Right-click on the IDLE shortcut and select properties. Set the "Start in" directory to be where you want default save path to be.
It seems like you can get idle into the directory you want if you run any module from that directory.
I had previously tried opening idlemain.py through the path browser. I was able to open and edit the file, but it seemed like I wasn't able to save my modifications.
I'm just glad to hear other people are having this problem. I just thought I was being stupid.
If you open a module, that sets the default working directory.
Start IDLE.
File -> Open to open your file. And set the current working directory.
In my case, the default directory is set to the directory from which I launched IDLE. For instance, if I launched IDLE from a directory called 'tmp' in my home directory, the default save path is set to ~/tmp. So start your IDLE like this:
~/tmp $ idle
[...]
On Windows (Vista at least, which is what I'm looking at here), shortcut icons on the desktop have a "Start in" field where you can set the directory used as the current working directory when the program starts. Changing that works for me. Anything like that on the Mac? (Starting in the desired directory from the command line works, too.)
For OS X:
Open a new finder window,then head over to applications.
Locate your Python application. (For my mac,it's Python 3.5)
Double click on it.
Right click on the IDLE icon,show package contents.
Then go into the contents folder,then resources.
Now,this is the important part:
(Note: You must be the administrator or have the administrator's password for the below to work)
Right click on the idlemain.py,Get Info.
Scroll all the way down. Make sure under the Sharing & Permissions tab,your "name"(Me) is on it with the privilege as Read & Write.
If not click on the lock symbol and unlock it.
Then add/edit yourself to have the Read & Write privilege.
Lastly,as per Ned Deily's instructions,edit the line:
os.chdir(os.path.expanduser('~/Documents'))
with your desired path and then save the changes.
Upon restarting the Python IDLE,you should find that your default Save as path to be the path you've indicated.
I am using windows 7 and by going to Start-> IDLE(Python 3.6 32-bit)
The click on properties and then in the shortcut tab go to
Start in and entering the desired path worked for me kindly note if IDLE is open and running while you do this you'll have to shut it down and restart it for this to work
If you locate the idlelib directory in your Python install, it will have a few files with the .def extension. config-main.def has instructions on where to put the custom config files. However, looking through these I did not find any configurable paths (your install may vary). Looks like you might need to crack open the editor code to alter it.
If you are using linux, you can create simple .sh file as presented below::
#!/bin/sh
cd /fullPath/PythonScripts/
idle
make the file executable by right click-> properties-> permissions-> check the execute as program checkbox-> done
Run the file :)