Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
{
"cells": [
{
"cell_type": "markdown",
"id": "bbefaee0",
"metadata": {},
"source": [
"# Ein Python-Modul entwicklen und veröffentlichen\n",
"\n",
"<br/>\n",
"<br/>\n",
"\n",
"Dieses Notebook finden Sie hier: TBD\n",
"\n",
"<br/>\n",
"\n",
"\n",
"\n",
"Dieses Notebook ist als freies Werk unter der Lizenz [Creative Commons Attribution-NonCommercial 3.0 Unported](http://creativecommons.org/licenses/by-nc/3.0/) verfügbar. Sie dürfen die Inhalte kopieren, verteilen und verändern, solange Sie die Urheber nennen und sie nicht für kommerzielle Zwecke nutzen."
]
},
{
"cell_type": "markdown",
"id": "30526362",
"metadata": {},
"source": [
"## Was ist ein Modul?\n",
"\n",
"- Ein Modul ist eine Datei, die Python-Definitionen und -Anweisungen beinhaltet. Oder anders gesagt: Jede Python-Datei ist ein Modul und der Name des Moduls ist der Dateiname ohne die Endung `.py`\n",
"- Ein Package ist eine Sammlung von Modulen. Hierfür liegen mehrere Module in einem Ordner, welcher auch eine Datei `__init__.py` enthalten muss. Dies unterscheidet ein Package von einem Ordner, der zufällig mehrere Module enthält."
]
},
{
"cell_type": "markdown",
"id": "edfaa8dd",
"metadata": {},
"source": [
"## Module verwenden\n",
"\n",
"- Python wird mit einer Bibliothek von Standardmodulen ausgeliefert. Ein solches Modul kann mit dem Befehl `import` importiert und anschließend verwendet weden."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0741b008",
"metadata": {},
"outputs": [],
"source": [
"import json"
]
},
{
"cell_type": "markdown",
"id": "af33edfc",
"metadata": {},
"source": [
"- Wenn wir nun versuchen ein Modul zu installieren, welches nicht in den Standardmodulen enthalten ist, dann kommt es zu einer Fehlermeldung."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c60f1b4",
"metadata": {},
"outputs": [],
"source": [
"import pandas"
]
},
{
"cell_type": "markdown",
"id": "de66aa56",
"metadata": {},
"source": [
"```\n",
"---------------------------------------------------------------------------\n",
"ModuleNotFoundError Traceback (most recent call last)\n",
"Cell In[1], line 1\n",
"----> 1 import pandas\n",
"\n",
"ModuleNotFoundError: No module named 'pandas'\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "5e9d899a",
"metadata": {},
"source": [
"## Module installieren\n",
"\n",
"- Module, die nicht in der Bibliothek von Standardmodulen enthalten sind, müssen vor dem Import installiert werden. Hierfür wird ein Paketverwaltungsprogramm verwendet. Dies ist im Normfall `pip`. Mit dem Befehl `pip install` können Pakete installiert werden."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53926ebe",
"metadata": {},
"outputs": [],
"source": [
"!pip install pandas"
]
},
{
"cell_type": "markdown",
"id": "1db617a4",
"metadata": {},
"source": [
"```\n",
"Collecting pandas\n",
" Downloading pandas-1.5.2-cp39-cp39-macosx_10_9_x86_64.whl (12.1 MB)\n",
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.1/12.1 MB 11.5 MB/s eta 0:00:00m eta 0:00:010:01:01\n",
"Collecting pytz>=2020.1\n",
" Downloading pytz-2022.6-py2.py3-none-any.whl (498 kB)\n",
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 498.1/498.1 kB 7.8 MB/s eta 0:00:00m eta 0:00:01\n",
"Collecting numpy>=1.20.3\n",
" Downloading numpy-1.23.5-cp39-cp39-macosx_10_9_x86_64.whl (18.1 MB)\n",
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.1/18.1 MB 11.6 MB/s eta 0:00:00m eta 0:00:01[36m0:00:01\n",
"Requirement already satisfied: python-dateutil>=2.8.1 in /Users/frede/Arbeit/repos/programmiertutorium/venv/lib/python3.9/site-packages (from pandas) (2.8.2)\n",
"Requirement already satisfied: six>=1.5 in /Users/frede/Arbeit/repos/programmiertutorium/venv/lib/python3.9/site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)\n",
"Installing collected packages: pytz, numpy, pandas\n",
"Successfully installed numpy-1.23.5 pandas-1.5.2 pytz-2022.6\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "5bbb3631",
"metadata": {},
"source": [
"## Doch was passiert hier eigentlich?"
]
},
{
"cell_type": "markdown",
"id": "4578dfe2",
"metadata": {},
"source": [
"### Python Package Index (PyPI)\n",
"\n",
"- `pip`lädt Pakete aus dem Python Package Index (PyPI).\n",
"- PyPI ist ein Sofware-Vezeichnis der Programmiersprache Python.\n",
"- PyPI umfasst knapp 420.00 Projekte (Stand: Dezember 2022)\n",
"- Jede:r kann sich auf PyPI (https://pypi.org) registrieren und ein Projekt erstellen.\n",
"\n",
"<div class=\"alert alert-info\">\n",
"<b>Hinweis</b> Der Begriff \"Package\" kann etwas verwirrend sein. PyPI spricht auch von Packages. Ein PyPI-Package kann ein einzelnes Python-Modul sein oder aber auch mehrere Python-Packages umfassen. \n",
"</div>"
]
},
{
"cell_type": "markdown",
"id": "e9e054ee",
"metadata": {},
"source": [
"### PyPI Testumgebung\n",
"\n",
"- Für Testzwecke gibt es die PyPI Testumgebgung (https://test.pypi.org)\n",
"- Diese funktioniert genau wie die reale Version und sollte verwendet werden um die eigene Konfiguration zu testen. "
]
},
{
"cell_type": "markdown",
"id": "7c602480",
"metadata": {},
"source": [
"## Mein erstes PyPI (Test)-Package"
]
},
{
"cell_type": "markdown",
"id": "bd3673fd",
"metadata": {},
"source": [
"### Struktur\n",
"\n",
"- TODO: Add screenshot"
]
},
{
"cell_type": "markdown",
"id": "e4db9691",
"metadata": {},
"source": [
"### pyproject.toml\n",
"\n",
"```toml\n",
"[build-system]\n",
"requires = [\"setuptools>=61.0\"]\n",
"build-backend = \"setuptools.build_meta\"\n",
"\n",
"[project]\n",
"name = \"Mein_Projekt\"\n",
"version = \"0.0.1\"\n",
"authors = [\n",
" { name = \"Mein Name\", email = \"Mein_Name@example.com\" }\n",
"]\n",
"description = \"Eine kurze Beschreibung für Mein Projekt\"\n",
"readme = \"README.md\"\n",
"requires-python = \">=3.7\"\n",
"\n",
"classifiers = [\n",
" \"Programming Language :: Python :: 3\",\n",
" \"License :: OSI Approved :: MIT License\",\n",
" \"Operating System :: OS Independent\",\n",
"]\n",
"\n",
"[project.urls]\n",
"\"Homepage\" = \"https://...\"\n",
"\"Bug Tracker\" = \"https://...\"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "646e592e",
"metadata": {},
"source": [
"### README.md\n",
"\n",
"```\n",
"# Mein Projekt\n",
"\n",
"Dies ist ein Beispielprojekt.\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "de1fcd4f",
"metadata": {},
"source": [
"## LICENSE\n",
"\n",
"```\n",
"Apache License\n",
" Version 2.0, January 2004\n",
" http://www.apache.org/licenses/\n",
"\n",
" TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n",
"\n",
" 1. Definitions.\n",
"\n",
" \"License\" shall mean the terms and conditions for use, reproduction,\n",
" and distribution as defined by Sections 1 through 9 of this document.\n",
"\n",
" \"Licensor\" shall mean the copyright owner or entity authorized by\n",
" the copyright owner that is granting the License.\n",
"\n",
" \"Legal Entity\" shall mean the union of the acting entity and all\n",
" other entities that control, are controlled by, or are under common\n",
" control with that entity. For the purposes of this definition,\n",
" \"control\" means (i) the power, direct or indirect, to cause the\n",
" direction or management of such entity, whether by contract or\n",
" otherwise, or (ii) ownership of fifty percent (50%) or more of the\n",
" outstanding shares, or (iii) beneficial ownership of such entity.\n",
" \n",
" [...]\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "86650a5a",
"metadata": {},
"source": [
"### Package für den Upload erzeugen\n",
"\n",
"```\n",
"python3 -m pip install --upgrade build\n",
"python3 -m build\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "300f78f8",
"metadata": {},
"source": [
"### Package auf Testserver hochladen\n",
"\n",
"```\n",
"python3 -m pip install --upgrade twine\n",
"python3 -m twine upload --repository testpypi dist/*\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ebcc1d5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}