I use Anaconda with Spyder that was installed in Anaconda to learn python.
The problem: when I'm trying to save python scripts by extending the file name to .py, the python script automatically gets saved in the Windows notepad. And when I try to open that again in Spyder it doesn't open.
In other words, in Spyder I saved the script by doing "file - save as - 'filename.py'"
and I tried to open the saved script by doing "file - open - 'filename.py'" in Spyder.
However, it doesn't work.
I two questions about this.
Is it normal for python scripts to be saved on windows notepad? If not, what is wrong here and how do you normally save python scripts with Anaconda?
Why doesn't Spyder open the notepad file, the python script I saved? I added the extention .py when I saved it but it is not opening in Anaconda Spyder regardless.
I realize this is a basic question to many and the answer may exist somewhere but I have a very hard time finding it and I'm hoping someone can help me solve this problem. Thanks.
Answer to the First question
Is it normal for python scripts to be saved on windows notepad? If not, what is wrong here and how do you normally save python scripts with Anaconda?
Check what default program is set
for opening .py file in your system you can change it by
rightclicking on .py file >expand open with > choose open with another
app and tick the option 'always use this for .py file'
Second question
Why doesn't Spyder open the notepad file, the python script I saved? I added the extention .py when I saved it but it is not opening in Anaconda Spyder regardless.
Check type of file your saving "the field below filename it should be
allfiles(*)" probably your script is saving "filename.py.txt" which is
not a proper format for python file
Related
I just uninstalled and reinstalled python on my Windows machine. Before I uninstalled my previous version I was able to just double-click on a python script and it would open the command prompt, run the script, and close automatically. After re-installing with the newest version (3.9), I am no longer able to execute the script like that with a double-click.
Clearly I had done something special last time to set that up for myself, but I don't remember what it was. Any idea how I can get that double-click deal going again?
Doing the following should fix it:
Right click on the .py file you want to open;
Open with -> Choose default program -> More options;
Select the python.exe file.
Explanation:
Your Python scripts have to be processed by another program called the Python interpreter. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program.
Installing a new version might have messed the path to the Python interpreter. The steps listed above will tell Windows to associate .py files with your Python interpreter, thus fixing the issue.
This link with Python on Windows FAQ might also be of help.
There will be an option of "Open With" after right-click on the file go and choose CMD. I hope it helps if not then sorry. Because I use Parrot OS
Save the following text to a file called something like python.reg (the .reg extension is important). You might need to modify the last line to be your exact path to python.exe!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\open]
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
#="\"C:\\Python2.7\\python.exe\" \"%1\" %*"
Find the python.reg file you just saved and double-click it to load those contents into your Registry. If you've performed one of the other operations in other answers (like "Open With"), those "UserChoice" settings are stored somewhere else in the Registry and will override the "Classes" setting shown in this script. So, do one or the other, don't combine them!
I am trying to open my python files with a double click. I normally open them in anaconda prompt which uses the powershell file found in C:\Windows\System32\WindowsPowerShell\v1.0. I tried using open with and navigating to this file, however then the promt window opens and immediately closes... the script should run continuously.
I also tried opening it with the "python (command line)" file which I found in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 2.7 I cannot open the location of that file for some reason using right click> open file location, however I tried to open my script using this but again the same thing happens.
It is frustrating as I need to close and open my scripts often. Each time I have to load up anaconda prompt, type in python and drag the file, and than press enter.
Any help would be appreciated.
I have installed Python 3.7 btw that I installed with ana and am trying to avoid reinstalling python as I have so many npm installs done that I did not keep a log of.
Try to open file/folder in other IDE like vscode, pyCharm or text editor.
Open IDE first after that click on file menu and select open option.Browse the file/folder and select it.
In powershell session typing python opens a Windows Explorer window "How do you want to open this file?" to select the program to open this file.
However the same python command works as expected (launches interpreter) in cmd.
The same issue when specifying python with a .py script name.
Do I need to fix something in registry keys or file associations? Why only powershell is behaving badly, but cmd works as expected?
EDIT:
Just resolved the issue:
PS > (get-command python.exe).Path
C:\Python\Python35_64b\python.exe
PS > (get-command python).Path
C:\Python\Python35_64b\Scripts\python
Apparently I had a file python without extension somehow stuck in one of the paths in %PATH% environment variable. After deleting this dummy file (how it got there?!) everything works fine.
Maybe this post still may help someone in the future (possibly myself)!
Still the question here is why cmd and powershell have a different order of searching for files in %PATH% with and without extensions (.exe)?
So I had python for a long time, but I didn't code just downloaded scritps and all that. I wanted to install python 3.7, when I did everything seemed to work fine, but my .py files didn't open.enter image description here
Images
You may tell windows what program should open py files with. If you want to open them with a text editor or a python interpreter installed, etc. Go to start menu and type "default programs", from there you need to tell windows what praogram you want to associate with py file
Just installed Python 2.7.3 on a Windows7 machine.
How do I get .py files to be associated with python (they are with notepad ATM) and how do I get the context menu shortcut for "edit in IDLE"? Somehow I didn't get that on this particular computer.
try making a .py file and then try to open it, and a window should appear asking you what to open it with, and then select idle in your program files.