You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _sources/where_to_put_your_code.rst.txt
+37-5Lines changed: 37 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Many scientists and engineers that do a little coding find they have a collectio
29
29
Options for Handling Your Code Collection:
30
30
------------------------------------------
31
31
32
-
1) Keep your code in one place, and copy and paste the functions y ou need into each new project.
32
+
1) Keep your code in one place, and copy and paste the functions you need into each new project.
33
33
34
34
35
35
DON'T DO THAT!
@@ -39,21 +39,53 @@ REALLY!
39
39
.......
40
40
41
41
42
-
It is really NOT a good idea to simply copy and paste these around for use with each project-- you will regret that!
42
+
It is really NOT a good idea to simply copy and paste code around for use with each project. You will end up with multiple versions scattered all over the place -- **you will regret that!**
43
43
44
-
It is also not a good idea to use the ``PYTHONPATH`` environment variable to set up a directory in which to dump stuff. (Google a bit if you want to know why).
44
+
2) Put your code in a single directory and add it to the ``PYTHONPATH`` environment variable
45
+
46
+
47
+
DON'T DO THAT!
48
+
..............
49
+
50
+
51
+
REALLY!
52
+
.......
53
+
54
+
``PTYHONPATH`` is shared by all installs of Python. What with Python2, Python3, virtual environments, etc -- it's really not a good idea.
55
+
56
+
If you don't believe me: **Google It**
57
+
58
+
59
+
What you should do is make a "package"
60
+
--------------------------------------
45
61
46
62
The best way to do this with Python is to use the Python package mechanism.
47
63
48
64
A Python "package" is a collection of modules and scripts -- we usually think of these as something carefully developed for a particular purpose and distributed to a wide audience for re-use -- the packages you can install with pip.
49
65
50
66
Indeed that is the case, but the "collection of modules and scripts" part can be used for your own code that no one else is ever going to touch, and the overhead is small if you use it only this way.
51
67
68
+
Why Don't People Tend to figure this out for themselves?
The Packaging Documentation is mostly about Making a "proper" package for distribution to a wide audience.
72
+
73
+
So newbies tend to either:
74
+
75
+
* Think: "I don't want/need to do all that", and then move on and copy and past their code around like they have already done.
76
+
77
+
or
78
+
79
+
* Go ahead and follow the instructions, and end up putting their tiny little not-useful-to-anyone-else package up on PyPi.
80
+
81
+
52
82
The challenge is that most of the documentation about python packaging is focused on creating a package of a library that you want to distribute to the community. In that case, it's very important to have full and proper meta data, tests, documentation, etc. As a result, the packaging documentation makes the whole process seem complicated and cumbersome.
53
83
54
-
But making a simple package for your own use can be very simple, and very useful.
84
+
Making a simple package just for your own use can be very simple, and very useful.
0 commit comments