I'm new to the vscode, so I wonder if it is possible to have an interactive python terminal with the same environment as a Jupyter notebook. The reason I ask this is I'm a Rstudio user, It is good to have a terminal down below and an area showing the variables I have for current space. I know in vscode I can see what variables I have. And I can have a terminal down below as python, but the problem is they don't share the working space, when I run a = 1 in Jupyter notebook, and type print(a) it will show "NameError: name 'a' is not defined." So is there a way to connect the 2 environments (or space)? Thanks!
I think this is what you want: Python Interactive window.
Install Python and Jupyter extension.
Read the docs and you can use right-click to open it.
Related
Im currently doing a project in VS Code using Jupyter Notebook, however I have some problems with the python interpreter. The problem seem to do with VS Code using two different interpreters.
I have chosen, what I think is the right interpreter, in the upper right corner, namely
However, when I check what version of Python is used in the terminal, then my version is 2.7.17, whereas it should be 3.8.5. I have already tried restarting the kernal, VS Code and changed between other interpreters. I dont know if it has something to do with the Julia env. as shown below:
Can anybody help me understand the problem, and maybe a fix?
The vscode integrated terminal uses the built-in powershell or cmd of windows. If you type python in the terminal, it will open the interactive terminal of the python version pointed to by the system environment variable. What you choose in the upper right corner of jupyter is just the jupyter notebook kernel, not even the python interpreter for vscode.
Ctrl+Shift+P to open the command palette, search for and select Python:Select Interpreter, then select the interpreter for the python file.
Of course, this operation is only valid for vscode. If you want the terminal to also use the interpreter you selected for vscoe in the Select Interpreter panel, use a virtual environment. When you activate the virtual environment in the vscode terminal, typing python will open the python interactive terminal under the environment.
For a couple of months I've had issues with working with virtual envs, python notebooks & jupyter in VSCode, for some reason, a lot of the time, it cannot find kernels I added, even though I can see them when running jupyter kernelspec list. It seems random whether they appear or not. Reloading the screen and restarting vscode does not help, neither does disabling and re-enabling the python and jupyter extensions. I tried both from the button, select kernel and through the command palette. I usually start vscode from the command line, with my virtual environment activated. Moreover, a lot of kernels which I've deleted a long time ago still show up in the list.
Vscode and laptop are both up to date.
I've had issues with the integrated jupyter notebooks before, at first formatting and autocomplete didn't work in the notebook (but they did in regular python files).
I'm on MacOS, if that matters.
Sorry to tell that this is a bug, see bug report:
Can't see or select Jupyter kernel's from Kernel drop-down
And now there's a workaround that:
Find where python is installed
Select the command Python: Select Interpreter
Next select Enter interpreter path
Next enter the path into the input box and hit Enter
This interpretr will now work in VS Code and you might need to re-load
VS Code just once more to get it working in jupyter extension.
Please have a try.
I'm testing codes from Colab, where you can just show the result without using print function, such as:
df.Quantity.dtypes
but in PyCharm, you have to run as the following to show the result:
print(df.Quantity.dtypes)
It's really time consuming if such commands are frequent.
How could I print out without using print functin in PyCharm just as Colab?
Thanks a lot!
You would have to create a Jupyter notebook, but note that this is a Professional feature, which means this won't work in PyCharm Community Edition.
Here's how to do it:
Create a new Python project, specify a virtual environment, and install the jupyter package.
Open or create an .ipynb file.
Add and edit source cells.
Execute any of the code cells to launch the Jupyter server.
More on PyCharms Jupyter features can be found here.
As an alternative, you could you the Python Console. Take a look at this question to learn more.
I am using VS Code in Windows 10.
I am able to use the dependencies in my conda environment if I Run the Python Script in Terminal. However, I am not able to use the environment in the Python Interactive shell.
For instance, I am using my datascienceenvironment which has the package fuzzywuzzy. I have included the env path into the settings.jsonas the python.pythonPath. But the Python version used in the Jupyter Notebook is the default anaconda base C:\\ProgramData\\Anaconda3\\python.exe
What is also extrange, is that if I run !conda list within the Notebook, I can see the fuzzywuzzy package.
What am I missing?
Thanks!
I'm a developer on the Interactive Windows. Priyatham has already pointed you in the right direction. Currently our Window tries to use the currently selected environment (the one in the lower left corner). But we didn't want to totally block customers if they didn't have Jupyter installed in each environment. So if the selected interpreter doesn't have Jupyter in the environment we'll check other environments on the system, looking for the closest python version match to the currently selected one. If we find something with Jupyter we'll launch the Interactive Window using that. In this case we do show a popup in the lower right indicating that we didn't find Jupyter and that we are falling back on a different environment, but this message can be pretty easy to miss.
I am using pycharm with a virtual environment set in preferences. That environment has installed python 2.7.13. I have installed anaconda in the virtual environment, which contains jupyter. I had the professional version but have allowed the subscription to lapse.
According to https://www.jetbrains.com/help/pycharm/2016.3/using-ipython-jupyter-notebook-with-pycharm.html I can create a notebook by opening the project window and using command-N, When I do this, I CAN select jupiter notebook but there is no way to enter the filename that they require.
Trying it another way, I use File->New->Python File and, for the name use test.ipynb. Pycharm accepts it but puts on a '.py' suffix, treating it as a normal python code file: test.ipynb.py.
Any ideas on how I get this to work?
I think u should try File->New->Jupyter Notebook, this works for me.