How to read a .py file after I install Anaconda? - python

I have installed Anaconda, but I do not know how to open a .py file..
If it is possible, please explain plainly, I browsed several threads, but I understood none of them..
Thanks a lot for your helps..
Best,

In the menu structure of your operating system, you should see a folder for Anaconda. In that folder is an icon for Spyder. Click that icon.
After a while (Spyder loads slowly) you will see the Spyder integrated environment. You can choose File then Open from the menu, or just click the Open icon that looks like an open folder. In the resulting Open dialog box, navigate to the relevant folder and open the relevant .py file. The Open dialog box will see .py, .pyw, and .ipy files by default, but clicking the relevant list box will enable you to see and load many other kinds of files. Opening that file will load the contents into the editor section of Spyder. You can view or edit the file there, or use other parts of Spyder to run, debug, and do other things with the file.
As of now, there is no in-built way to load a .py file in Spyder directly from the operating system. You can set that up in Windows by double-clicking a .py file, then choosing the spyder.exe file, and telling Windows to always use that application to load the file. The Anaconda developers have said that a soon-to-come version of Anaconda will modify the operating system so that .py and other files will load in Spyder with a double-click. But what I said above works for Windows.
This answer was a bit condensed, since I do not know your level of understanding. Ask if you need more details.

You can use any text editor to open a .py file, e.g. TextMate, TextWrangler, TextEdit, PyCharm, AquaMacs, etc.

Related

How to execute .py file with double-click

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!

Pycharm 2020.1.2 - .py file - Open File in Project

I came back to pycharm for a project from SublimeText and updated to Pycharm 2020.1.2, I needed to quickly run a .py file, but when I double click the file, it opens the script in a view where I can edit but not run, so every time I have to go to File->Open File in Project. I don't remember having to do that in earlier versions of Pycharm, how can I circumvent that and always have Pycharm open a .py file in Project view?
You started PyCharm in the light edit mode, check this blog post https://blog.jetbrains.com/idea/2020/04/lightedit-mode/
I also have pycharm and usually I do Right click on the file -> open with -> pycharm
your problem does not seem a big deal. the problem is that you are using 'the editor' of PyCharm.
see this picture below of my system:
when you right-click on a .py file and choose 'Edit with PyCharm', you use the simple editor of PyCharm. not the Debugger.
If you click on anywhere else on the window(not on a file), you see the option 'Open Folder as PyCharm Project' (if you do not have this option, reinstall PyCharm and check this option in PyCharm setup wizard), like the picture below:
now if you choose this option, PyCharm will open your whole folder as a project, and you have python console, terminal, debugger, and whatever you want.
these 2 pictures below, show differences between this 2 mode:
Edit with Pycharm:
you can see in this mode you have no option for running and debugging your code. just an editor.
Open Folder as PyCharm Project
in this mode, you will see you have full options for running and debugging, python console, terminal, and so on...
so you see, in your first picture, when you select 'Open File in Project' in PyCharm Editor mode, it looks like you are opening this file by pressing 'Open Folder as PyCharm Project' in your folder. so if you open your folder as a PyCharm project, you do not need to do this all the time for running you code.

Can't open python scripts, asks to choose how would you like to open this file

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

Python files created do not save as python file

https://drive.google.com/file/d/0BwR0ium7uufRWnhXWWNFcVJ3S2c/edit?usp=sharing
The files that are blank and say "Credit Card Balance" and "mine" are the files which I created by opening up a new document in IDLE and creating a file. The ones with the little pictures and say ps2_newton are programs which I downloaded off of the internet. I can't open my files which I created like they are regular programs and have to open them under notepad to see the code. Why is this? How can I change my files to look and act like the ones I downloaded?
The files you downloaded have an extension of ".py", which tells Windows to open them with the Python launcher, while the ones you created have no extension, or an extension of ".txt", which tells Windows to open them in Notepad.
Since ".py" and ".txt" are both "known extensions", and you have Explorer configured to hide known extensions (which I believe is the default in all versions of Windows), it doesn't show them to you. However, you can see the difference in the icons.
You can configure Explorer to show all extensions, but this site is not the place to ask about that—try SuperUser.
Meanwhile, when you save your scripts, make sure you save them with a .py extension (or, if they're Tkinter or other GUI apps, with a .pyw extension).
I had the same problem. But I just deleted all of the é's and á's etc. And it worked! So try that IF it is an .py file. Otherwise I understand if it does not work becouse it isn't a python file. You change that by doing this: Save as. Just simply type .py after the file name.
PS Sorry for my bad english...

IDLE not integrated in desktop

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.

Categories

Resources