Python Forum

Full Version: Simple code works in Jupyter but not VS Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
Thanks snippsat!

That did the trick.