|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/creating-python-packages/ |
| Your Learning Plan →Your personalized Python learning plan | https://realpython.com/account/learning-plan/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest&_from=nav_library |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/search?kind=exercise&kind=quiz&_from=nav_library |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Mentor AI →NewYour personal Python mentor | https://realpython.com/mentor/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Live Courses →Live, instructor-led Python courses | https://realpython.com/live/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Unlock All Content and Become a Python Expert →Get unlimited access to all Real Python has to offer | https://realpython.com/account/join/?from=navbar_learn |
| Unlock All Content →Become a Python Expert | https://realpython.com/account/join/?from=navbar_learn |
|
More
| https://realpython.com/lessons/creating-python-packages/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Contributor | https://realpython.com/jobs/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?intent=navbar&next=%2Flessons%2Fcreating-python-packages%2F |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-basics-modules-packages |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-basics-modules-packages |
|
| https://realpython.com/courses/python-basics-modules-packages/#team |
| Python Basics: Modules and Packages | https://realpython.com/courses/python-basics-modules-packages/ |
| Philipp Acsany | https://realpython.com/courses/python-basics-modules-packages/#team |
| Course Slides (.pdf) | https://realpython.com/courses/python-basics-modules-packages/downloads/python-basics-modules-packages-slides/ |
| Sample Code (.zip) | https://realpython.com/courses/python-basics-modules-packages/downloads/python-basics-modules-packages-code/ |
| Ask a Question | https://realpython.com/lessons/creating-python-packages/#discussion |
| https://realpython.com/feedback/survey/course/python-basics-modules-packages/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/python-basics-modules-packages/disliked/?from=lesson-title |
| Contents | https://realpython.com/lessons/creating-python-packages/#description |
| Transcript | https://realpython.com/lessons/creating-python-packages/#transcript |
| Discussion (2) | https://realpython.com/lessons/creating-python-packages/#discussion |
| 00:00 | https://realpython.com/lessons/creating-python-packages/#t=0.745 |
| Let’s create a package structure. | https://realpython.com/lessons/creating-python-packages/#t=0.745 |
| I’m here in my terminal, | https://realpython.com/lessons/creating-python-packages/#t=2.537 |
| but you can totally create those files in your Windows Explorer or your | https://realpython.com/lessons/creating-python-packages/#t=4.035 |
| Mac Finder or on your Linux file application | https://realpython.com/lessons/creating-python-packages/#t=8.955 |
| app, which name I don’t know, | https://realpython.com/lessons/creating-python-packages/#t=14.035 |
| but you can also follow me along with the terminal. | https://realpython.com/lessons/creating-python-packages/#t=16.075 |
| 00:20 | https://realpython.com/lessons/creating-python-packages/#t=20.855 |
| Navigate to the desktop and create a folder named | https://realpython.com/lessons/creating-python-packages/#t=20.855 |
| packages_example/. | https://realpython.com/lessons/creating-python-packages/#t=25.925 |
| Then navigate into this folder. | https://realpython.com/lessons/creating-python-packages/#t=27.71 |
| 00:34 | https://realpython.com/lessons/creating-python-packages/#t=34.375 |
| And in this folder, create another folder. | https://realpython.com/lessons/creating-python-packages/#t=34.375 |
| And this one, | https://realpython.com/lessons/creating-python-packages/#t=37.106 |
| you name mypackage/. | https://realpython.com/lessons/creating-python-packages/#t=38.375 |
| 00:43 | https://realpython.com/lessons/creating-python-packages/#t=43.295 |
| The packages_example folder is called the project folder, | https://realpython.com/lessons/creating-python-packages/#t=43.295 |
| or project root folder, | https://realpython.com/lessons/creating-python-packages/#t=48.095 |
| because it will contain all the files and folders in the | https://realpython.com/lessons/creating-python-packages/#t=49.905 |
| packages_example/ project. | https://realpython.com/lessons/creating-python-packages/#t=53.395 |
| 00:55 | https://realpython.com/lessons/creating-python-packages/#t=55.135 |
| The mypackage/ folder will eventually become a Python package. | https://realpython.com/lessons/creating-python-packages/#t=55.135 |
| It isn’t one right now because it doesn’t contain any modules. | https://realpython.com/lessons/creating-python-packages/#t=59.495 |
| So to change that, hop over to IDLE and create a new editor window. | https://realpython.com/lessons/creating-python-packages/#t=63.455 |
| 01:10 | https://realpython.com/lessons/creating-python-packages/#t=70.005 |
| As mentioned before, to make a folder a Python package, | https://realpython.com/lessons/creating-python-packages/#t=70.005 |
| you need to have a __init__ file in it. | https://realpython.com/lessons/creating-python-packages/#t=73.125 |
| So never forget to have __init__ in it. | https://realpython.com/lessons/creating-python-packages/#t=75.925 |
| 01:20 | https://realpython.com/lessons/creating-python-packages/#t=80.192 |
| Yeah, | https://realpython.com/lessons/creating-python-packages/#t=80.192 |
| and as mentioned before, also this file can be empty. | https://realpython.com/lessons/creating-python-packages/#t=81.215 |
| So without adding any content to it, | https://realpython.com/lessons/creating-python-packages/#t=84.815 |
| save a new file from your IDLE editor window as | https://realpython.com/lessons/creating-python-packages/#t=87.665 |
| __init__.py | https://realpython.com/lessons/creating-python-packages/#t=92.605 |
| in the mypackage/ subfolder of your packages_example/ folder | https://realpython.com/lessons/creating-python-packages/#t=95.615 |
| 01:44 | https://realpython.com/lessons/creating-python-packages/#t=104.355 |
| Then open another window and add the following function: | https://realpython.com/lessons/creating-python-packages/#t=104.355 |
| def greet(name): | https://realpython.com/lessons/creating-python-packages/#t=108.765 |
| And then on the next line, | https://realpython.com/lessons/creating-python-packages/#t=112.845 |
| indented, print(). | https://realpython.com/lessons/creating-python-packages/#t=116.855 |
| And then let’s do an f-string: f"Hello, {name}!" and the closing parentheses. | https://realpython.com/lessons/creating-python-packages/#t=119.335 |
| 02:12 | https://realpython.com/lessons/creating-python-packages/#t=132.155 |
| So there is a greet() function that takes name, and inside | https://realpython.com/lessons/creating-python-packages/#t=132.155 |
| greet(), | https://realpython.com/lessons/creating-python-packages/#t=136.865 |
| you call the print() function, and then you print a string, Hello, with the | https://realpython.com/lessons/creating-python-packages/#t=137.435 |
| name that was passed into the function. | https://realpython.com/lessons/creating-python-packages/#t=142.295 |
| 02:25 | https://realpython.com/lessons/creating-python-packages/#t=145.435 |
| Save this file as module1.py | https://realpython.com/lessons/creating-python-packages/#t=145.435 |
| in the same folder as the __init__ file. | https://realpython.com/lessons/creating-python-packages/#t=147.685 |
| And to make the package complete, | https://realpython.com/lessons/creating-python-packages/#t=153.305 |
| create a new file in your IDLE editor with this code— | https://realpython.com/lessons/creating-python-packages/#t=155.345 |
| def depart():—which takes one parameter, | https://realpython.com/lessons/creating-python-packages/#t=160.855 |
| which is name. | https://realpython.com/lessons/creating-python-packages/#t=163.725 |
| 02:45 | https://realpython.com/lessons/creating-python-packages/#t=165.514 |
| And inside the function body, again | https://realpython.com/lessons/creating-python-packages/#t=165.514 |
| a print() function call. | https://realpython.com/lessons/creating-python-packages/#t=168.575 |
| And this time, you use an f-string saying goodbye, | https://realpython.com/lessons/creating-python-packages/#t=169.835 |
| and then in curly braces the name. | https://realpython.com/lessons/creating-python-packages/#t=174.115 |
| 02:59 | https://realpython.com/lessons/creating-python-packages/#t=179.595 |
| Just like before, you’ll save this file in the mypackage/ subfolder. | https://realpython.com/lessons/creating-python-packages/#t=179.595 |
| And you name this file module2.py, | https://realpython.com/lessons/creating-python-packages/#t=183.185 |
| 03:11 | https://realpython.com/lessons/creating-python-packages/#t=191.055 |
| and that’s a package. | https://realpython.com/lessons/creating-python-packages/#t=191.055 |
| With this structure, the files, and the code in place, | https://realpython.com/lessons/creating-python-packages/#t=192.466 |
| you are now ready to import and use these modules in another module. | https://realpython.com/lessons/creating-python-packages/#t=196.375 |
| Dec. 27, 2023 | https://realpython.com/lessons/creating-python-packages/#comment-2b560bd2-d32f-4f80-957a-dea037ea951d |
| Jan. 3, 2024 | https://realpython.com/lessons/creating-python-packages/#comment-cad1577a-9487-4a9c-bf6c-ecc7a89b0d4f |
| Useful Terminal Commands | https://realpython.com/terminal-commands/ |
| Using the Terminal on Windows | https://realpython.com/courses/using-terminal-windows/ |
| Your Python Coding Environment on Windows: Setup Guide | https://realpython.com/python-coding-setup-windows/ |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/introducing-python-packages/ |
| Overview | https://realpython.com/courses/python-basics-modules-packages/ |
| https://realpython.com/lessons/working-with-packages/ |
|
Python Basics: Modules and Packages (Overview) 01:44
| https://realpython.com/videos/modules-packages-overview/ |
|
Working With Modules 00:27
| https://realpython.com/videos/working-with-python-modules/ |
|
Creating Modules 01:55
| https://realpython.com/videos/creating-python-modules/ |
|
Calling an Imported Object 01:45
| https://realpython.com/lessons/call-imported-object/ |
|
Understanding Namespaces 00:27
| https://realpython.com/lessons/understanding-namespaces/ |
|
Accessing Objects From Inside a Module 01:02
| https://realpython.com/lessons/accessing-module-objects/ |
|
Using Dot Notation for Imported Objects 00:54
| https://realpython.com/lessons/dot-notation-imported-objects/ |
|
Adding Objects to a Namespace 01:29
| https://realpython.com/lessons/adding-namespace-objects/ |
|
Breaking a Program Into Modules 00:45
| https://realpython.com/lessons/break-program-into-modules/ |
|
Exercise: Import and Use a Module 08:00
| https://realpython.com/lessons/exercise-import-use-module/ |
|
Exercise: Fix a Broken Import 08:00
| https://realpython.com/lessons/exercise-fix-broken-import/ |
|
Renaming an Imported Module 02:42
| https://realpython.com/lessons/rename-imported-module/ |
|
Importing Objects From a Module 03:20
| https://realpython.com/lessons/import-module-objects/ |
|
Summarizing Import Statements 03:18
| https://realpython.com/lessons/summarizing-import-statements/ |
|
Exercise: Import Specific Functions 08:00
| https://realpython.com/lessons/exercise-import-specific-functions/ |
|
Taking Advantage of Namespaces 01:04
| https://realpython.com/lessons/namespace-advantages/ |
|
Introducing Packages 01:16
| https://realpython.com/lessons/introducing-python-packages/ |
|
Creating Packages 03:21
| https://realpython.com/lessons/creating-python-packages/ |
|
Working With Packages 04:16
| https://realpython.com/lessons/working-with-packages/ |
|
Summarizing Import Statements for Packages 01:40
| https://realpython.com/lessons/package-import-statements/ |
|
Importing Modules From Subpackages 03:57
| https://realpython.com/lessons/importing-modules-from-subpackages/ |
|
Exercise: Import From a Package 08:00
| https://realpython.com/lessons/exercise-import-from-package/ |
|
Python Basics: Modules and Packages (Exercises) 02:55
| https://realpython.com/lessons/python-modules-packages-exercises/ |
|
Python Basics: Modules and Packages (Quiz) 05:30
| https://realpython.com/lessons/modules-packages-quiz/ |
|
Python Basics: Modules and Packages (Summary) 01:37
| https://realpython.com/lessons/modules-packages-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover