Jupyter in VSCode - python

enter image description here
At first, jupyter notebook works fine. BUT, whenever I try to use the other ipynb file, jupyter notebook does not work and send this message. How should I deal with this?

Have you checked which python interpreter you are using in the Jupyter Notebook?
With the different names of the .ipynb file, it will take the different kernels, and it is stored in the database.

First of all, create a virtualenv. Open the terminal using Ctrl+Shift+`.
In the console, type python3 -m venv venv.
This will create a folder named venv in your working directory.
Now, in the bottom left corner, you will find the selected python interpreter. Click that and change it to venv.
(If windows raises permission error, In your vsCode settings, add the following lines.)
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
Now delete all previous terminals and open a new terminal.
Install the required packages using pip and carry on.

Related

Visual Studio Code not opening any python interpret

I am having an issue with opening and running python on VS Code. In particular, I cannot open any python interpret regardless of having python installed on the computer and the python extension in VS code.
1 week ago, there was no issue with that, I opened VS Code, followed the instructions and python was running (however without any packages or libraries). Because I use python for Data Science projects, I decided to integrate Jupyter notebook - here again, no issues.
Afterwards, I got the idea that I should be able to import libraries and run codes in file_name.py, not only file_other_name.ipynb, so I was trying to create an environment in my project folder that will store installed packages by typing py -3 -m venv .venv .venv\scripts\activate and python -m pip install matplotlib in the terminal. Unfortunately, that did not work when running a basic script - getting a message "Activate.ps1 is not digitally signed. You cannot run this script on the current system."
Hence, I set up the powershell to Set-ExecutionPolicy -ExecutionPolicy Unrestricted. Once, I restarted VS Code, the current environment started showing a message 'Select Python Interpret'. I tried to reinstall the python extension and select from the Command Palette (Ctrl + Shift + P) any of the python interprets, that it is giving me but nothing happens. The message does not change regardless of how many times I have specified which interpret to open. Any idea how I can open the python interpret once again?
enter image description here
There's a default setting called "python.terminal.activateEnvironment": true, so every time you create an virtual environment and select it as your interpreter, don't forget to open a new integrated Terminal(Ctrl+Shift+`) to activate it.
[EDIT]
When you open a new integrated Terminal, there'll be an statement executed automatically: that's a file in your created .venv, which is by red underlined in the following screenshot. Then you get a virtual name prefix before PS, that means you've activated it successfully.
If the Activate.ps1 isn't executed automatically, turn to the .venv folder, copy its absolute path then run it in Terminal still can activate the environment.
Then go on development, like installing the required module:

How to fix Visual Studio Code Jupyter notebook error?

VScode for python runs perfectly, without any error, problems starts whenever I try to run Jupyter notebook inside VScode.
It starts with Ipython Kernel loading and then it shows Command Failed Error. Any fix for this ? I have no idea what's the problem and I don't know much about the environment and stuffs also.
Thank You.
From your picture, VSCode said Command failed, and it's a very long command. It mainly includes two parts: activate the conda base environment and change the vscode python environment through "Python" extension. And from the top right of the picture, it shows the jupyter server start failed.
So you can try to do two things:
First one: change the environment. Instead of using conda, download and install a global python from the official website. And recommend creating a virtual environment. Then select the environment instead of conda base environment.
Second one: reinstall or downgrade the 'Python' extension(if the first one not work).
This problem can be caused by the package in the environment, so I recommend you just change to another environment.

Open .ipynb in Anaconda Jupyter Notebook on double-click (macOS)

I've been trying to figure out how I can open a .ipynb file on double-click on a Mac, so the file opens with Anaconda and then automatically opens Jupyter Notebook with the file contents.
I have tried creating an application through Automator that opens with a jupyter_lab command, but the issue is that Jupyter lives in Anaconda, so this method is not working. See these articles for my steps: https://samedwardes.com/2020-01-31-open-ipynb-with-double-click/ and Open an ipython notebook via double-click on osx
I have also tried installing nbopen with the following:
python3 -m pip install nbopen
This works, and then I can run nbopen file.ipynb through the terminal, but I want to be able to bypass this step and do it while in file explorer, physically looking at the file instead.
I have ran the recommended command for osx to integrate it with file manager ./osx-install.sh but I just get zsh no such file or directory and can't really find any help with figuring out why this is pushing back an error.
Any suggestions?
I have this "convenience issue" as well, and didn't go for the nbopen route, but instead, I just made a batch script (I named it jupyter-notebook.bat) that calls certain conda functions, and pretty much initiates things like how double clicking works. In the script, I just have this:
call "C:\Users\XYZ\Anaconda3\Scripts\activate.bat"
call conda activate myEnvironment
call python C:\Users\XYZ\Anaconda3\Scripts\jupyter-notebook-script.py %1
Lastly you just need to configure that every .ipynb opens up using your jupyter-notebook.bat script.
For consistency, I placed the script in my Anaconda folder. And if you also have nb_conda_kernels installed in your base environment, you'd have access to the other environment you've created as well from there.

How to specify python3 kernel in jupyter in pyCharm?

Here is my setting
and this is my script
I am trying to use jupyter notebook in pyCharm, but it kept using python2 instead of python3.
Any idea about this problem?
Add:
this pic is running jupyter notebook in chrome.
My problem was that I had multiple kernels, and PyCharm launches the default kernel. One approach might be to configure PyCharm to specify the kernel of choice to start up, I didn't investigate how to do that. I simply changed the default kernel in Jupyter and this worked for me (I have a virtualenv for tensorflow). c.MultiKernelManager.default_kernel_name = 'tensorflow'.
The preferences image you show is indeed how you would setup your interpreter for PyCharm, but that's not what the output/logging of PyCharm looks like. I'm guessing that's a jupyter-notebook display, which means you are running into the issue in jupyter-notebook and not PyCharm. So you need to change your setup for jupyter. Based on some quick searching pip install jupyter will install a python 2.7 version of jupyter. Sounds like what you want is
pip3 install jupyter
which will install the python3 version for you. You will likely have to uninstall your current version of jupyter.
When you kick off Jupyter-notebook from within PyCharm there is a configuration which is created. If the configuration is initially 2.7 ( I think it defaults to the current interpreter), and then keep using that same configuration, it wouldn't matter the state of the current project interpreter because it would be using the value saved in the run configuration.
You can modify your run configuration by
Run | Run...
Edit Configurations...
Select your Jupyter Notebook run configuration on the left (here is untitled4)
Make sure the python interpreter is correct here on the right
I was able to start a jupyter notebook like this and get it to output python 3 by doing this. Hope this is what you are needing.

I cannot use jupyter notebooks in pycharm

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.

Categories

Resources