I recently installed PyCharm. Now when I run a *.py file from the command line, PyCharm opens up and tries to create a project - every time! I close PyCharm, try to run the file from cmd, PyCharm opens back up and interferes. Is there any way to prevent this? Thanks.
Try removing .py file's association. By right clicking on any .py files > properties > general tab > Opens with > Change
Related
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.
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.
I'm setting up my home computer for basic python development. I've managed to install Anaconda through the command line but I'm not sure how to make .py files run through the Anaconda interpreter when double-clicked.
i.e. I did this on my Windows computer at work by right clicking on a .py file and then choosing open with > open with another application > navigating to {C:\Users\\AppData\Local\Continuum\anaconda3} > clicking on python.exe and then clicking 'open'. Is there an equivalent way of doing this on Linux? I'm running Pop!_OS.
I've tried clicking 'open with' but there was no option to open with another application. I also wouldn't know what type of file I would be looking for whereas I knew in Windows I was looking for a .exe
I've also tried right clicking on a .py file, going on the 'Permissions' tab, checking the box for 'Allow executing file as a program' and going to Files > preferences > Behaviour and changed the Executable Text Files option from 'Display them' to 'Run them'.
The most common way on linux to make things executable is by adding the executable flag to the file. On command line, if your file is called script.py:
chmod +x script.py
It is important that your script starts with a description of how to execute it.
For python, your script should start with:
#!/usr/bin/env python
Also, for clarification, there is no .exe file in Linux. The equivalent to that is the previously mentioned executable flag.
How to set Spyder as default program for Python file? This question has been asked over and over in here and here. I looked around, there still isn't an answer.
I want to click on a .py file, and open it in Spyder. Instead of, opening Sypder from Terminal, then go to File > open. I'm using a Mac.
This question was asked as early as 2013. It's now 2018!
Steps:
Download the spyder-mac-app.zip archive. Unarchive it to
/Applications
Edit the /Applications/Spyder.app/Contents/MacOS/Spyder file to launch the right environment of Spyder, e.g.:
#!/bin/sh
$HOME/anaconda3/envs/tensorflow/bin/spyder $#
Launch Spyder from Finder to verify that Finder is launching as expected.
Install duti and run duti -s org.spyder .py all
Right click any .py file in Finder, click Get Info In Open with menu, select Other and navigate to 'Applications. Select Spyder, Press Add and Click on Change All in Info menu.
Here is the rundown (seen here: Change Default App For File On Mac):
Right Click File
Click Get Info
Click Open With Dropdown
Choose The App
Click Change All
If Asked Click Continue
To run Python files (.py) with Windows CMD.exe, I SHIFT + Right Click on my project folder which contains all of my Python code files. Doing this shows a menu containing the option Open command window here, which I click to open CMD.exe with the prompt C:\Users\Name\FolderLocation\ProjectFolder>. I then type the python command, and the file I want to run in my project folder (python MyFile.py) which runs the file, of course.
What I would like to know is if there is a way I can setup a shortcut to open CMD.exe with my project folder opened/ being accessed so then all I have to do is type python and the file name? Thanks
Create a shortcut to cmd.exe.
Get properties on that shortcut, and there's an entry for the current working directory. (They change the name of that field every other version of Windows, but I believe most recently it's called "Start In:".) Just set that to C:\Users\Name\FolderLocation\ProjectFolder.
Now, when you double-click that shortcut, it'll open a cmd.exe window, in your project directory.