Mastery course: Section 10 lesson 5 About

I am new to Python and I am facing this confusing situation. As we know after rmoving the requests package from global installation I am not able to execute the code

import requests
response = requests.get("http://yahoo.com")
print(response)

and we know according to the lecture that when I run the command
pipenv shell

Ok, so to be able to run it globally without running the above comman I have added the path to python entry in the settings.json file as follows after extracting the full path by another command… see as follows:

"code-runner.executorMap": {

    "javascript": "node",
    "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
    "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    "zig": "zig run",
    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    "php": "php",
    //"python": "python -u",
    "python": "/Users/Sarmad Alsaadi/.virtualenvs/mastery_course-fYXotm-6/Scripts/python",
    "perl": "perl",

despite following the instruction in the lecture I am stll getting (requests) not installed but when I run
pipenv shell
it works

I am still not understanding what is the code runner despite I installed the said extension from the VScode.
I am very confused. Please some help.

1 Like

this create env if not created and also activate at the same time;
once you activated env you can import libraries which you have installed in this env using command pipenv install requests
if you work outside of this env then requests module is not be available

Virtual Enviroment

2 Likes

Thank you so much. That is exactly what I understood but confusion started when Mosh introduced the extension of (code-runner). If, we could at the the VS code, execute a program from either the Terminal or from the menu (Ctrl+F5) why should we use code-runner and even have to modify the settings.json. However, I will go back to the env topic and review it more thoroughly and I will apprreciate any other additions from you if you have.

1 Like

without code runner extension you have to manually execute programming script like i did in above image for python

if you have installed code runner extension you just need to click on top right conner icon or use shortcut ctrl+f5

sometime you want to write script in a terminal like this python app.py for executing the app.py file instead of using icon or shortcut this is where you can play with setting

2 Likes

Thank you for having the time to answer my queries. Now i could do it. The code runner at first could not see the path to the virtual environment until i discovered that that this path contained two separated words (sarmad alsaadi) then i only surriunded them with quotes and voila it worked.
One thing remains confusing a red underline is still appearing under the word (requests)

2023-02-16_18-50-20

despite the fact that the package is installed in the ve and code run normally

1 Like