8

I'm trying to use vscode with jupyter via the python extension. My pipfile looks like this:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[packages]
opencv-python = "*"

[requires]
python_version = "3.6"

[dev-packages]
ipykernel = "*"
ipython = "*"
jupyter = "*"

To start the ipython interpreter i follow these steps:

  • $ pipenv install
  • $ pipenv shell
  • $ code .
  • using the Python: Select interpreter, i select the pipenv environment
  • run code

when i got to the code block by pressing shift + enter, i see the errors:

enter image description here

Code block:

#%%
import cv2

I have also tried using all dependencies in the [packages] section, reinstalling my pipenv from scratch, and repeating the above process.

Always the same error, what am i missing?

$ code -v
1.41.1
26076a4de974ead31f97692a0d32f90d735645c0
x64

Preston
  • 7,399
  • 8
  • 54
  • 84

2 Answers2

12

I had the same issue do the following

1- remove python and fresh install new python the latest version has pip in it

2- open terminal as administrator and run the following command:

  pip install ipykernel --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
MJ X
  • 8,506
  • 12
  • 74
  • 99
  • 3
    Thanks, install everything with pip3 and it worked. By the way, I didn't remove python, just following step 2 is enough. – Kevin Patel Oct 27 '21 at 15:17
  • 1
    Thanks , the 2nd command worked for me too. Also I had to create .ipynb file manually in VSCODE. – Ani Mar 19 '22 at 21:36
3

Turns out that the python I had installed python3.x, but not python3.x-dev.

You can install this using:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update -y && sudo apt upgrade
sudo apt install python3.8 python3.8-dev

Upon opening vscode i then hit ctrl + shift + P and selected Python: Select Interpreter and selected the virtual env containing ipykernel.

Preston
  • 7,399
  • 8
  • 54
  • 84
  • Yep, this did it for me too. Everything was installed properly but I couldn't get the interpreter to run from VS Code. Turns out I was pointed at the wrong interpreter! – Raydot Mar 05 '21 at 18:37