I've been using the Interactive window in VSCode to test my code and the kernel suddenly stopped working.
There are two available kernels: Python 3.9.9 64-bit (windows store), and Python 3.9.7 64-bit
The default being loaded each time I open the window is the former, which gives the 'Kernel process Exited' error, and the other one says it requires ipykernel installed, which is already installed.
Is there a way to fix the kernel issue or is there a better way to test my python code?
Do you have any recommendations for how to call functions from a python file in VSCode?
About kernel question, It basically means the program has finished running. If the code is not giving the answer you are expecting, you may try the following two ways, or even have to provide code.
1. Restart Kernel:
2. Create virtual environment.
python -m venv .venv
Selecting it as python interpreter and activating it in terminal, then select it in Jupyter and it will notice you install required ipykernel.
Reference: Create a virtual environment and Select and activate
an environment
Then, call functions from a python file in VS Code. Treat it as a module, see the example that i call the func() from a.py in both b.py and jupyter notebook:
Installing the jupyter notebook and restarting the kernel worked for me.
pip install notebook
Related
I pip installed the sportsreference package in my command prompt and it shows successful. Yet when I try to call it in my Jupyter Notebook it says no module named sportsreference.
Any help on what I'm doing wrong?
The interpreter that your Jupyter uses to run the cells is not the one you installed that package into. Remember you can have not only different versions of Python interpreter, but also different virtual environments associated with each Python interpreter in your machine.
So either install the package in the interpreter that Jupyter uses, or run the Jupyter from the interpreter you've installed that package into.
The simplest solution is to install it in a Jupyter cell with:
!pip install <your_package_name>
the ! allows you to execute command.
To check which interpreter currently runs your code you can check the output of:
import sys
print(sys.executable)
I'm trying to use anaconda with visual studio code but keep getting this error message every time I try to run something.
enter image description here
enter image description here
What Iv'e tried/confirmed:
Python 3.9.1 is installed and Iv'e got no problems running codes in VSC when I use the standard enviroment or inside a command terminal.
The version of python the anacoanda says it is using is 3.8.5. Should it be 3.9.1 or is that normal?
Python and anaconda were added to path during installation - Iv'e already made that mastake before.
Presumably anaconda is installed properly. I can access the navigator and command prompt.
Its not the code that Iv'e writen. I tried simply writing print("Hello") and it gives me the same error.
Installed the latest version of anaconda.
I have encountered the same problem. The reason is that VS Code uses the powershell terminal by default, but powershell does not activate the conda environment by default.
Therefore, it is recommended that you use the cmd terminal or other terminals that come with the system. (Because in VS Code, the terminal it uses is to integrate the terminal from the system and it not only supports the powershell terminal.)
Solution: for example, switch to using cmd terminal:
Reference: Integrated terminal in VS Code.
I'm currently experiencing some troubles with jupyter notebook and system shell commands. I use nb_conda_kernels to be able to access all of my conda environment from a jupyter notebook launched in base environment, and this works perfectly in most of my use cases. For simplicity sake, let's assume I have 2 environments, the base one, and one named work_env. I launch jupyter notebook in the base environment, and select the work_env kernel upon opening the notebook I'm working on.
Today I came across this line:
! pip install kaggle --upgrade
upon execution of the cell (with the work_env kernel correctly activated), pip installed the kaggle package in my base environment. The intended result was to install this package in my work_env. Any ideas on how to make shell commands execute in the "right" environment from jupyter notebook?
Try specifying the current python interpreter.
import sys
!$sys.executable -m pip install kaggle --upgrade
sys.executable returns the path to the python interpreter you are currently running. $ passes that variable to your terminal (! runs the command on the terminal).
Aliases expand Python variables just like system calls using ! or !! do: all expressions prefixed with ‘$’ get expanded. For details of the semantic rules, see PEP-215
from https://ipython.org/ipython-doc/3/interactive/magics.html
-m is used to run a library module (pip in this case) as a script (check python -h). Running pip as a script guarantees that you are using the pip linked to the current python interpreter rather than the one specified by your system variables.
So, in this way you are sure that pip is installing dependencies on the very same python interpreter you are working on (which is installed in your current environment), this does the trick.
I don't know why but after half day using my kernel 'geomatic' in jupyterhub, something crash. My notebook doesn't work anymore... After some researches, I understand that issue comes from python version used by notebook or console. It's a bad one python: 3.6.3 whereas in my kernel terminal (source activate geomatic) I have python 3.6.6. I don't know why but this difference makes crash my scripts and I can't import geopandas in a notebook for example.
always install from "Anaconda Prompt" if using Anaconda Navigator in windows. I had a similar issue and installing the package using Anaconda prompt. Make sure the python version from Anaconda prompt and jupyter are the same (should be)
I'm pretty new to programming so forgive my ignorance.
When installing certain python packages/modules in the cmd prompt I am able to import them fine when using Jupyter Notebook. But some modules Jupyter Notebook cannot import without installing via Conda first. Why is this?
The problem seems to be related to system and environment that you are using and not the programming :)
Since you are a beginner, let us understand the concepts first rather than solving the problem.
Python code is run on an interpreter that is installed on your machine.
Jupyter is a web application that takes code using a given language's interpreter. So Jupyter, on its own doesn't run your code. It uses the interpreter installed on a system(your local machine).
Conda is a package manager and also an environment manager. That means using conda, you can create a virtual environment on your machine and that virtual environment can have its own installation of an interpreter. This virtual environment can have its own copy of the packages/modules as well.
Now comes the best part: The jupyter notebook can be asked to use any of the interpreters including the ones installed on a virtual environment.
So most likely, you are running the jupyter notebook from an environment which doesn't have the required dependencies. So either run the jupyter notebook outside the environment or install the required packages in the environment where your jupyter notebook is running.
To know which environment is being used by your jupyter notebook, run below lines from the jupyter notebook cell:
import sys
sys.executable
If you don't get something like /usr/bin/python then the jupyter is running inside an environment. So you have to install all the packages/modules inside that environment only.