Connect Ipython Notebook to PyCharm Python console - python

PyCharm 4.5.4 has an option "Python Console" (Tools -> Python Console) which runs a Python interpreter with proper paths and allows to debug Django projects (for example). Aslo it has an option of using IPython if it is present, and the question is if it is possible to connect an IPython Notebook or QtConsole to this interpreter?
I've tried using %connect_info and %qtconsole, but it doesn't work, probably that means that the kernel is not running (like if I were to run just $ ipython). If so can it be started without a lot of trouble?

Turned out to be easier than I thought.
So, in order to use IPython Notebook to debug local Django App in the Django Console, you need to add django-extensions library to your project's interpreter, append it to settings.py INSTALLED_APPS, then go to the "Terminal" tab in PyCharm (its options are in Settings -> Tools -> Terminal), navigate to the folder with manage.py if you are not there, and use a command
python manage.py shell_plus --notebook

Related

How do I activate a VSCode environment from ssh?

I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.

Pycharm Run Linux Command before Console

Hi I am currently using pycharm to work on a python project. I am mostly running the code on a remote server which I have easy ssh access to. I currently have pycharm setup that I can easily upload/download files and use the ipython console with my environment. However, to fully be able to use the resources of the server I need to be able to run a linux command before running my python files or calling ipython so that I can have the resources I need to debug and whatnot. Is there a way to tell pycharm to run a specific command before starting my remote environment for the ipython console. (i.e instead of it doing conda activate environment; ipython it would do linux command; conda activate environment; ipython?
Thank you

Run ipdb with seperate terminal in pycharm

Information
I faced an annoying thing with PyCharm in the last couple of days. I'm trying to use ipdb to debug my program instead of pycharm debugger but I can only open it in thepycharm i/o console or in the python console.
Question
Is there anyway that I can open the debugging session in the terminal window? or even in a new terminal window? I alos want to be able to open the session from the debugging button, and don't write any line like python src/main.py by my self in the terminal
The main reason I want to do it so I can have an auto complete as I get from ipython in the terminal, but I couldn't find a way to open the debugging session in terminal window, is there anyway to do it? and plugin that can help? the autocomplete that the python console gives me is very weak and not really helping me
System information
Pycharm 2018.3
Centos 7 64bit
Updated
Here is a simple workaround that you can fork an open-source project from git and add a patch for persistent history. To install IPDB you can use the following command to fork the latest version:
pip install git+https://github.com/gotcha/ipdb.git
To install git projects using pip, visit pip install from git repo branch. Just make sure that your IPython version is 6.0 or higher.
Implementation Info: can be found in these Articles. Visit references: Use of IPDB and IPDB Persistent History .
Otherwise, you can also use pudb instead. It enables getting to a real ipython shell from the debugger and all the commands there are saved.
To launch Debugging Session, go to Pycharm Windows-Tool-Bar at the bottom and right click on terminal as follows:
To Open Terminal in Window Mode:
When terminal is open in window mode, then you can open multiple debugging sessions as given below:
[ + ] to open multiple Sessions:*
At the end you can use the following command to launch debugging sessions using this command:
$ python -m ipdb /path/my_test.py
This will initiate your debugging session using IPDB in PyCharm terminal window.
Here is a test result:

How to run a file in IPython console as default instead of terminal?

I started a new project in PyCharm. I have Anaconda 3.6 installed. So, in PyCharm, I selected the Anaconda python.exe as project interpreter.
When I first ran PyCharm, it used the IPython console as "default" console to run my script. Then I restarted my PC and now PyCharm uses the terminal when I run my scripts. Why? I don't want to use the terminal, coming from Anaconda Spyder IDE. I'm used to IPython, I like it and I want to use it.
How can I completely disable the terminal and use only the IPython console?
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:
Unlike Spyder, PyCharm has no graphical indicator showing that this is an IPython console.
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 follow these two steps:
Go to File > Default Settings > Build, Execution, Deployment > Console and make sure to select Use IPython if available.
Go to Run > Edit Configurations and select Show command line afterwards
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
In the new version of Pycharm, you have a different option in Edit Configuration.
Go to Run > Edit Configurations and select Run with Python console

Django /manage.py runserver doesn't work (Windows)

I have installed python 2.7.10 in windows. I installed django in path c:python27/scripts/with a command pip install django and created project with command django-admin startproject mysite from the same path.
Now to run server i cd to path c:python27/scripts/mysite and ran a command manage.py runserver/ manage.py runserver 0.0.0.0:8000 And this has no any effect.
where did i go wrong, and also i couldn't run with python console. and i couldn't redirect to my project from python CMD. all i did is from windows console.
Edit:
Screenshot of execution
First step was to set the environment variable.
windows key + pause or Control Panel\System and Security\System
Advance system settings (this will open system property)
navigate to Advanced tab > Environment variable
Edit path - append ;c:\python27 in variable value field
Restart CMD
then /python manage.py runserver should work
Trying setting up a virtualenv for your project.
This same issue happened to me when trying to launch the test server
python .\manage.py runserver
from PowerShell on Windows 10. According to the Django site, there might be an issue with the type of arguments being passed from PowerShell.
My workaround was to use a virtualenv. Once that was setup with django installed via pip, the runserver command worked.
The best solution is to install Python from Microsoft Store. In this case, you won't have to worry about the Environmental Variables and Path. Windows will detect all that automatically.
Try this fix guys:
1. Right click on the windows icon/start on the bottom left and run Windows Powershell as admin.
2. Than type cd ~/ and later change the path again to the project folder.
3. type python manage.py runserver and press enter.
had the same problem. fixed it by checking python and django version compatibility. If you're still battling with this update one or the other or ensure they're both compatible with each other in the virtual'env' you're setting up.
good luck.
I think you forgot to add python to environment variables. So, During the installation, click the checkbox named "Add Python 3.9 to PATH" to add in environment variables. or you can simply add the path later.
When you open the command prompt on windows, the default directory might be C:\WINDOWS\System32>
Here, you have to change the directory by just adding cd to the default directory. Then copy the directory of where your project is and paste with one space. So it will be:
C:\yourfolder\yourproject>
Next, use the comman which is, python manage.py runserver
That's all 😅
After setting C:\Python in the environment variables, issuing the following command helped:
py manage.py runserver

Categories