Python Part 5 - Modules

preview_player
Показать описание
By Andy Brown

The key to writing Python programs is to make effective use of modules (both those built in to Python, and external ones). This tutorial shows you how to import, install, list and use modules.

Chapters
00:00 Topic list
01:07 Importing modules
05:18 Built-in modules
07:21 Examples of built-in modules
12:11 Installing external modules
16:01 ModuleNotFoundError
19:32 Viewing and listing modules

If you'd like to help fund Wise Owl's conversion of tea and biscuits into quality training videos you can join this channel to get access to perks:

Рекомендации по теме
Комментарии
Автор

Thanks Andy and Sven. Well explained and good examples. Thanks for the lesson! Thumbs up!!

wayneedmondson
Автор

Thankss
Looking forward to the next vid

bigger
Автор

How do you get the setting changes at 18:40? I don't see that same code.

andrewhalpern
Автор

Harika olmuş
Seve seve izliyorum
Eline emeğine sağlık

alivali
Автор

Note that, using 'print(sys.executable)' tells the user the host folder path of the python.exe file currently being used. Folks, this is useful when the user (= me) has mixed up the use of the pip installation route with the use of the Anaconda prompt for installation. The user should stay with one method. I mixed the two methods up and it took two days to unravel it all ! Also, the path of the python.exe file has to be entered into a Power BI start-up file for the case when the user is running python in Power BI.

JHatLpool
Автор

For the method to fix ModuleNotFoundError at 18:49, I get the following error message:

'c:\VSCODE' is not recognized as an internal or external command,
operable program or batch file.

My code works fine if I do [ctrl] + [f5]

If I were to do the first method,



I still get the ModuleNotFoundError.

Edit 1:
But if I do "print(sys.path)"

I get as one of the many paths.

Edit 2:
After doing, "pip show requests" in the terminal, I have found that requests is installed in . Even though earlier I followed the steps correctly and still found the file in the VirtualEnvironment folder. I am guessing that THIS is the problem. How do I fix it?

FINAL EDIT:
In the terminal, after accessing the virtual environment created earlier (tutorial), I did "python -m pip uninstall requests" then "python -m pip install requests". It fixed the problem immediately. I did not have to append nor change settings.json .
However, I ran into the problem with character mapping. As such, I followed what Kai Weissmann did and wrote instead of "print(response.text)" .

mastertoru
Автор

For the problem with coderunner, I found the following to work for me:

to set up the virtual environment :

python3 -m venv virtualfolder
set-executionpolicy unrestricted -scope process


(I found that the use of python3 rather than python means that coderunner can correctly locate the module when it is installed. I found that I had to allow powershell to run scripts, and eventually found the execution policy toggle - rather than doing it indefinitely within powershell)

then to install the module:

python -m pip install requests

(perhaps Sven can explain why python3 does not work for this although perfectly good to set up the virtual environment)

My initial impressions of python is that all of these steps are unwieldy workarounds - why isn't this structured correctly & set out in a straightforward fashion ?

Chris-hoby
Автор

It seems that the 2nd method of installing modules does not work when your file path has space in it... not sure if this was the reason why i failed.

I have got traceback error on the first append path method also. Shows ” failed to establish a new connection: [Errno 11001]

lastdance
Автор

Hi Andy, thanks for the nice tutorial. Couple of short questions. Is it not possible to use import datetime? When I try to do so I get a yellow (warning?) triangle (I am using Spyder). Ignoring this triangle on next line if I write print(datetime.today()), I get error message in the terminal window AttributeError: module 'datetime' has no attribute 'today'. Second question. When I type import sys, I again get yellow triangle. Upon hovering the mouse over it, it reads " 'sys' imported but unused (pyflakes E) ". I ignored this triangle and on next line wrote print(sys.version). Code runs without any issues. Now not sure when to "respect" the yellow triangle and when not?

zubairkahn
Автор

I can't find the same codes in Setting in order to fix the "Requests module not found" problem. I used to use Anaconda for Python a few years ago and such problems never popped up. Would it be better to switch back to Anaconda?

aatsw
Автор

Hi, i'm getting an error at line print(response.text). UnicodeEncodeError: 'charmap' codec can't encode character '\u2009' in position 223181: character maps to <undefined>. What should I do here?

youHONKA
Автор

I got crazy because I could not install the requests module in my virtual Enviroment but I keep installing it in my main python Interpreter on my machine ( If you need to install the module in your dedicated Python VirtualEnviroments specifically created in the previous lesson, you would need first to activate your virtual Enviroment with ".\activate.ps1" as in the previous lesson and then follow the instructions of this video...

gianpaolo
Автор

Hello! When I try to install requests, it says the requirement is already satisfied in a different file location. I am in the virtual environment, but I have it already for other projects elsewhere. When I try to import requests, it doesn't know where it is, any idea how to resolve?

JoeManGuy
Автор

Mine has this notification while trying to print requests:
Traceback (most recent call last):
File "c:\Users\lhviet\Desktop\ca nhan\hoc python\Python\tutorial\05 modules\installing modules.py", line 6, in <module>
print(response.text)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input, self.errors, encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u1ee9' in position 335: character maps to <undefined>

Can anyone tell me how to fix it?

hoangvietlee