Skip to content

Understand the basics of creating local modules and packages, and able to build a own python packages / modules just like Pandas or NumPy

Notifications You must be signed in to change notification settings

ayerfph/Creating-Local-Python-Package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Definitions

Under your package folder:

__init__.py

  • file in Python serves a crucial role when building local packages or modules. Its primary function is to designate a directory as a Python package, allowing its contents (other modules and sub-packages) to be imported and utilized within your project.

utils.py

  • this file usually you setting up the classes for the local module / packages. This can be more different files and classes defines it. In order the class is included to the local module / package, you need to import it in the __init__.py file.

After you setup the local package / module:

my_script.py

  • You can now use it in your scripts by importing the package in your python file.

One more thing:

  • There's an easy way to install all the packages / modules you need all in one.
  • You need to set it up by creating a requrements.txt
# What's inside of requirements.txt?
matplotlib
numpy==1.15.4
pycodestyle>=2.4.0

Note: you can just put the name of the packages / modules you want to installed, you can specified the exact version or you can just put nothing and it's all depends on your required module / package to use. After listing all the modules / packages, you can just go in terminal and type:

pip install -r requirements.txt

Warning: make sure that your terminal is located where the requirements.txt is.

Basic Python Package / Local Module Structure

my_directory/
├── my_package/
│   ├── __init__.py
│   └── utils.py
│ 
├── __init__.py
├── my_script.py

About

Understand the basics of creating local modules and packages, and able to build a own python packages / modules just like Pandas or NumPy

Topics

Resources

Stars

Watchers

Forks

Languages