Python Forum
Simple code works in Jupyter but not VS Code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple code works in Jupyter but not VS Code
#1
Hi Python Experts,

I am extremely new to Python and am trying to work out a small problem.

I am using the latest version of Anaconda Navigator and am launching Jupyter Notebook and VS Code from Anaconda.

In the Python Notebook in Jupyter I can run this code and get the expected result.

import requests
url = 'https://www.bing.com/'
requests.get(url)
<Response [200]>

However, when I run this code using VS Code and the Powershell terminal I just get another prompt (if that is the correct term).
I saved the identical code in the file getURL.py

PS C:\Users\Matthew> python getURL.py
PS C:\Users\Matthew>

I have downloaded and imported the pip install requests for VS Code

I'm wondering if there's something I need to do in VS Code to make sure it's actually sending a request out to the web. Since I launch both Jupyter and VS Code from Anaconda I thought the environments would be set up in a similar way. Apologies if I don't have the terminology correct.

Thanks in advance to anyone who responds. It's much appreciated.

Matt
Reply
#2
Running as script you need print().
Jupyter Notebook show output automatic as it work the same as a Python REPL(read-eval–print-loop),as you probably seen start with >>>.
import requests

url = 'https://www.bing.com/'
print(requests.get(url))
For some setup tips look at VS Code from start.
Reply
#3
Thanks snippsat!

That did the trick.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 327 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 1,009 Nov-15-2023, 06:56 PM
Last Post: jst
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 484 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Code works but doesn't give the right results colin_dent 2 715 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,444 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  help me simple code result min and max number abrahimusmaximus 2 907 Nov-12-2022, 07:52 AM
Last Post: buran
  python multiple try except block in my code -- can we shorten code mg24 10 6,139 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  faster code for my code kucingkembar 19 3,258 Aug-09-2022, 09:48 AM
Last Post: DPaul
  Simple encoding code ebolisa 3 1,445 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,805 Feb-21-2022, 10:52 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020