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
Related
In R Studio, Matlab, and in some Python IDEs (like Thonny) you can see a list of the variables in your environment, together with some summary information like values, type etc.
Is there a way to do this in VSCode without going into debugging mode?
Seems like the closest as it gets to the RStudio Environment window is by installing Jupyter. Then you can type #%% in your .py file and a small "Run Cell" button will appear. Running the cell will open the "Python Interactive Window". There you can click the "See Variables Active" button to open up the Variable Window and see your variables... still a bit painful in comparison with RStudio, this should be integrated in VScode's IDE.
See steps here:
https://code.visualstudio.com/docs/python/jupyter-support-py#_variable-explorer-and-data-viewer
VS Code has an IPython mode with a dropdown box called Variables that basically does exactly this.
To enter IPython mode all you need to do is highlight a piece of code and hit Shift+Enter
The first time you do it there might be a bit of setting up to do but it was pretty easy to get it working on my Mac. Not sure what it's like on Windows/Linux though
Note: When I use VS Code I open it from the terminal (simply enter the command 'code') after I've activated my conda environment. That way the IPython interpreter uses my preferred conda environment when it launches.
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
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
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 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)