Jupyter notebooks already have a popular simple magic inline command for this, as mentioned above. (Examples)
Hopefully Jupyter could instead / also support this PEP?
(A separate toml file would probably not be a viable alternative.)
How would the PEP work for e.g.
torch? Typically you have to look up and copy this:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117
Should scripts be able to specify a package index? It would be possible to implement “some” features, for example being able to add extra index locations. However, it is difficult to know where to draw the line
Maybe it is better to keep it simple. But it is unfortunate that ML use cases would be out of scope then.
Here is a random simple example of a single-file script / Jupyter notebook using torch.
From the Python Packaging User Survey:
What should the PSF and PyPA focus on? → #1 by far: Making Python packaging better serve common use cases and workflows
What should the packaging community do to be “an ecosystem for all”? → #1 by far: Support more interoperability between Python packaging tools
This is it. Simple scripts are a very common use case. Currently there’s no good workflow for them, and no interoperability between tools. This PEP addresses both.
What Python packaging tools do you use? → #1 by far: pip
I prefer to use several Python packaging tools, rather than a single tool → Most disagree
I would love to see support for this PEP integrated in pip as
pip run. But the PEP has to be accepted first of course.
What do other packaging managers do better than Python Packaging?
- Better deployment of dependencies when installing projects
- Better systems for managing dependencies within a project
For example they provide simple one-liner dependecy requirement syntax for simple script “projects”.
For example F# has a popular directive
#r "nuget: FSharp.Data" roughly equivalent to e.g.
#r "pip: numpy". (Not an embedded
Python packaging is too complex
“Simple things should be simple, complex things should be possible.”
A very simple solution is needed. A simple script can be written in seconds to minutes. Specifying its dependencies should not break the flow. Writing a simple declaration with trivial / no syntax should be easy from muscle memory.
There are many viable ways this could be done with minimal syntax complexity:
__dependencies__ = "numpy Pillow"
import numpy # requires: numpy
import PIL # requires: Pillow
%pip install numpy
%pip install Pillow
There are only very few matches on Github for
#Dependencies, so more complex syntax for disambiguation is not necessary.
Keeping the syntax similar to the existing pyproject.toml would be nice (for experts that already know it) I guess.
But if it’s not possible to keep it simple it doesn’t serve the common use case and becomes pointless.
Learning the simple one-liner syntax doesn’t seem like a real issue for experts.
This would be way too complex:
__pyproject_toml__ = """
dependencies = [
Can proponents of a more pyproject.toml-like approach show an example of similar simplicity as the PEP?
Transforming a script containing simple PEP declarations into a full pyproject.toml project would be trivial if it’s ever desired.