Dan
Dan

Reputation: 45752

Jupyter runs terminal in virtual environment but ipynb in base python

I am trying to run Jupyter in a conda virtual environment. I have activated my environment and if I run python from the terminal it runs the virtual environment correctly.

However if I launch jupyter from within my virtual environment (by opening a Windows command prompt, typing conda activate hqb-api2 and then jupyter lab --no-browser), the .ipynb files are running a kernel using the base python installation rather than the virtual environment. You can see this by printing sys.prefix:

enter image description here

However, if I launch a terminal in Jupyter instead of a .ipynb file, then it correctly uses the virtual environment:

enter image description here

lastly, here is a subsection from pip list showing the relevant jupyter packages:

enter image description here

What am I doing wrong?

Upvotes: 0

Views: 1906

Answers (1)

pvy4917
pvy4917

Reputation: 1842

As per this documentation: Installing the IPython kernel

However, if you want to use a kernel with a different version of Python, or in a virtualenv or conda environment, you’ll need to install that manually

Executing the following command will fix the issue.

python -m ipykernel install --user

Upvotes: 2

Related Questions