Python version : 3.6.1
Pycharm version : 2018.1 EAP (Professional Edition)
My python interpreter runs in interactive mode ON ITS OWN!!
I just ran the script
I ran the python script in PyCharm in the way that I usually did.
The interpreter had worked very well until the last night(2018/01/31) but...
But the interpreter has been changed like this
it has been changed in interactive mode AUTOMATICALLY.
I did just sleep, wake up and run it.
This is what actually I had seen
ran like this until the last night.
(I brought it from Google because I don't have a capture.)
PyCharm Preferences
But that doesn't mean that -i is in the interpreter option.
I got some solution that unchecking
"Show command line afterwards" box works, but I cannot find it.
import sys
print(sys.flags.interactive) # 0
Checked interactive flag is False.
It is kinda useful using interactive interpreter but I am now just uncomfortable for it.
How do I change it to uninteractive???
Go to Run > Edit configurations... menu. Select Python > your-script-name on the left and un-check the option Show command line afterwards on the right:
You'll find the option in Run > Edit Configurations
Related
I'm unable to find/execute the interactive mode in visual studio code - could you guys step-by-step me? Seems like a ridiculous question, I guess, but none of the waypoints I Googled seem to work;
"View > Other Windows > Interactive menu commands)" https://learn.microsoft.com/en-us/visualstudio/python/python-interactive-repl-in-visual-studio?view=vs-2019
I don't have "other windows"
If there's something I need to install, please let me know.
(Yes, I'm a beginner).
In VSCode, you can enter the Python interactive window in the following places:
Option 1
F1 -> Python: Create Python Interactive Window
This is the Python interactive window that comes with VSCode.
You can enter the interactive window without inputting instructions.
Please use "Ctrl+Enter" to execute the code:
Option 2
Ctrl + Shift + `
This is the cmd window that comes with the VSCode integration computer.
We need to enter the command "python" to enter the Python interactive window:
PS
For more information about using Python in Visual Studio Code, you can refer to the official VSCode documentation: Python in VSCode.
If you have the Python extension, you can use the Python Interactive feature (this is a IPython/Jupyter console, which can run parts of your code as 'cells', i.e. snippets of code executed in one go).
This article writes about the interactive window and many more possibilities of using Jupyter in VS Code: https://code.visualstudio.com/docs/python/jupyter-support-py
Best option
When editing Python code, select something and press Shift + Enter. This will open the interactive window and run your selection as a single cell.
I have personally been annoyed many times by accidentally pressing Shift + Enter instead of Enter on a line of code which (alone) would be a syntax error. Then, one day I decided to start using this feature consciously.
Terminal fallback
Press:
Ctrl+`
This opens a system shell (bash, or on Windows: Powershell or cmd).
Run python, or ipython if you have it (pip install ipython), and use the interactive window. In the terminal, you can also execute your script, by typing python myscript.py arguments.
If you type # %% in your vscode editor while editing a .py file,
then a interactive cell is created and it can be evaluated. The nice part of this is that # denotes comment in a .py file so you can save and run your code as a script
I installed VSCode, downloaded official Python 3.6.4.
VSCode detected and set the environment right - I do see "python.pythonPath" user setting set correctly.
But, when using VS Code using Ctrl+F5to run a Python file, I am always getting asked for "select environment" and it shows me two options
- Python
- Python Experimental
What is this "Python Experimental"? How can I get rid of getting interrupted every time I try to run a script?
Run > Add Configuration... => Choose one of the two options.
After doing this it will no longer prompt you.
Ctrl+F5 is a shortcut to Start without Debugging What you want is just running a file according to your post. To run a python file in the integrated terminal, right-click your editor window and Run Python File in Terminal. It should open up a terminal window within VS Code and run as normal. It also takes into account the environment you are currently using whenever you run it.
To answer your other question about Python Experimental, it is an option to use the experimental debugger, an alternate version of a Python Debugger. You can read the instructions here
Is there a interface in Pycharm where we can simply type in some commands and run it ?
Something like in Matlab, we can type in "a = 1; b = 2; c = a+b" then we get ans=3.
Thanks
PS: we know we can create a python file in Pycharm and run it, e.g., "a = 1; b = 2; c = a+b; print(c)" but it is not as convenient as a command window.
Short answer from the docs:
To launch an interactive console
On the main menu, choose Tools | Run Python console.
Description:
REPL console
PyCharm also helps those who love the full control of an
interactive console: on the Tools menu, you can find commands that
launch the interactive Python or Django consoles. Here you can type
commands and execute them immediately. Moreover, PyCharm's interactive
consoles feature syntax highlighting, code completion, and allow
viewing the history of commands (Ctrl+Alt+E or Up/Down arrows while in
the editor).
PyCharm also makes it possible to run in console source code from the
editor — just make your selection, and then press Shift+Alt+E (Execute
selection in console on the context menu of the selection).
Independent of Pycharm, you can also access the REPL in the terminal (or cmd shell on Windows) by typing
python
at the prompt.
In PyCharm, you navigate to the View -> Tool Windows menu and toggle the Terminal window See image here. It will likely show up at the bottom of your IDE window.
Another very good (and more general option) is to use IDLE. From its Wikipedia entry...
IDLE is intended to be a simple IDE and suitable for beginners, especially in an educational environment. To that end, it is cross-platform, and avoids feature clutter.
It ships with basically every standard version of Python since 1.5.2 so I'm pretty sure you have it available on your system (I've checked with Linux and Mac OS X).
To fire up IDLE in Python2, enter: /path/to/python/bin/idle where /path/to/python/bin is where you find the Python executable.
For Python3, use idle3 instead.
You should see a new separate terminal window open up (with syntax highlighting and all!)See image here.
Find the attached screenshot..
You can observe the o/p of the editor in Run window.
You can also find Python Console and Command Terminal at the bottom of the Pycharm.
I am using PyCharm IDE with Anaconda distribution.
when I run:Tools > Python Console... PyCharm uses ipython console which is part of Anaconda distribution.
But it using a default profile.
I already tried add option --profile=myProfileName in Environment variables and in Interpreter options in Settings > Build, Execution, Deployment > Console > Python Console
But it keeps using default profile.
My question is how to set different ipython profile in PyCharm?
Short answer:
Go to File > Default settings > Build, Execution, Deployment > Console and select Use Ipython if available
Go to Run > Edit Configurations and select Show command line afterwards
Tip: Run selected parts of your code with ALT + SHIFT + E
The details:
If you've selected Anaconda as the project interpreter, IPython will most likely be the selected console even though it neither looks nor behaves like the IPython console you are used to in Spyder.
I guess you are used to seeing this in Spyder: enter image description here
I'm also guessing that the following is what you're seeing in PyCharm in the Console Window:
enter image description here
Unlike Spyder, PyCharm has no graphical indicator showing that this is an IPython console. So, to make sure it's an IPython console and make it behave more or less like the IPython console you are used to from Spyder, you should try to follow these two steps:
Go to File > Default Settings > Build, Execution, Deployment > Console and make sure to select Use IPython if available. enter image description here
Go to Run > Edit Configurations and select Show command line afterwards enter image description here
Now you can run selected parts of your code with ALT+SHIFT+E more or less exactly like in Spyder.
If this doesn't do the trick, you should check out these other posts on SO:
Interacting with program after execution
Disable ipython console in pycharm
I am a beginner of spyder IDE for Python.
To use spyder IDE, I command "spyder" on anaconda console with python 2.7
After that, I try to print "hi"
But I encounter an error message
"No python shell is currently selected to run hu.py Please select or open a new Python interpreter and try again"
How could I solve this problem?
I saved my file on C:\Anaconda\practice_jhk
from __future__ import print_function
print ("hi")
You can specify the Spyder's Run Settings in Run -> Configure (F6). By default "Execute in current Python or IPython console" is selected and you probably do not have any open console in Spyder.
You can select "Execute in a new dedicated Python console" option and Spyder will automatically open a new console for you. Or you can leave the dafault option and create a new console yourself in the Consoles menu.
I have had the same problem. I am not able to fix it but I am able to successfully run the program the following two ways and I don't find any problems till now:
By selecting IPython console (not the one with the Kernel id as its tab) then running your program.
By selecting "Execute in new dedicated Python console" from Tools --> Preferences --> Run.
I was getting the same error message, but then realized I was not directing the PATH to my Python interpreter file at all. How I solved the problem:
Go to Tools > PYTHONPATH manager
Select "Add path"
Find and select your Python interpreter folder (for me this was C:\Python27)
Try, tools -> Reset sypder to factory default. Then, click on the run button in the dialog box.
I had this issue when I didn't have the python console pane open.
To resolve this, in the top bar go to: view -> panes and turn ipython console on.
This fixed it for me.
You might have unexpectedly closed the Ipython console window which is open by default and that caused the error.
Go to Consoles > New console(default settings)