Phát triển gói Python
James Fulton
Climate informatics researcher
Trong example_script.py
import mysklearn
Cây thư mục cho gói có các gói con
home/
|-- mysklearn <-- cùng thư mục
| |-- __init__.py
| |-- preprocessing
| | |-- __init__.py
| | |-- normalize.py
| | |-- standardize.py
| |-- regression
| | |-- __init__.py
| | |-- regression.py
| `-- utils.py
|-- example_script.py <-- cùng thư mục
Trong example_script.py
import mysklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mysklearn'
Cây thư mục
home/
|-- mypackages
| |-- mysklearn <---
| |-- __init__.py
| |-- preprocessing
| | |-- __init__.py
| | |-- normalize.py
| | |-- standardize.py
| |-- regression
| |-- __init__.py
| |-- regression.py
`-- myscripts
`-- example_script.py <---
Cây thư mục cho gói có các gói con
mysklearn/
|-- __init__.py
|-- preprocessing
| |-- __init__.py
| |-- normalize.py
| |-- standardize.py
|-- regression
| |-- __init__.py
| |-- regression.py
|-- utils.py
Cây thư mục cho gói có các gói con
mysklearn/ <-- thư mục ngoài
|-- mysklearn <--- thư mục mã nguồn bên trong
|-- __init__.py
|-- preprocessing
| |-- __init__.py
| |-- normalize.py
| |-- standardize.py
|-- regression
| |-- __init__.py
| |-- regression.py
|-- utils.py
Cây thư mục cho gói có các gói con
mysklearn/ <-- thư mục ngoài
|-- mysklearn <--- thư mục mã nguồn bên trong
| |-- __init__.py
| |-- preprocessing
| | |-- __init__.py
| | | |-- normalize.py
| | | |-- standardize.py
| |-- regression
| | |-- __init__.py
| | |-- regression.py
| |-- utils.py
|-- setup.py <-- script cài đặt ở thư mục ngoài
# Import required functions from setuptools import setup# Call setup function setup(author="James Fulton",description="A complete package for linear regression.",name="mysklearn",version="0.1.0",)
số phiên bản = (số chính) . (số phụ) . (bản vá)
# Import required functions from setuptools import setup, find_packages # Call setup function setup( author="James Fulton", description="A complete package for linear regression.", name="mysklearn", version="0.1.0",packages=find_packages(include=["mysklearn", "mysklearn.*"]),)
pip install -e .
. = gói ở thư mục hiện tại-e = chế độ chỉnh sửa (editable)Cây thư mục cho gói có các gói con
mysklearn/ <-- di chuyển tới đây
|-- mysklearn
| |-- __init__.py
| |-- preprocessing
| | |-- __init__.py
| | |-- normalize.py
| | |-- standardize.py
| |-- regression
| | |-- __init__.py
| | |-- regression.py
| |-- utils.py
|-- setup.py
Phát triển gói Python