by pmarreck · 2y ago · 0 comments
Especially if it's a nice TUI app like this looks
EDIT: Guys, in my experience, virtual environments do not fix this problem in all cases. At least, not sufficiently for me (after getting used to Nix's guarantees, for example). Not to mention, there's multiple ways/attempts at creating and working with virtual environments: https://twitter.com/pmarreck/status/1735363908515295253). See below comment.
python -m venv ~/my-venvs/<name>
source ~/my-venvs/name/bin/activate
pip install <package>
but stuff like this would usually get installed globally, and your projects would instead have a venv.personally my favorite tool is pyenv, which allows you to have many versions of python on your machine as well as many virtualenv (which are assigned to any version you have installed)
then it is as simple as
pyenv virtualenv <version> <name>
pyenv virtualenv 3.11.1 xyz
and to activate pyenv activate xyz
this allows you to keep every project you have isolated not only to the packages required to run it, but also the python version required.I work on a handful of projects that run on 3.10, 3.11 and 3.12. Each has their own independent python version, and within that version they also have their own python packages (pip environment).
At the end of the day these are simply directories on disk.
but also...
> but stuff like this would usually get installed globally
well, you just killed (apparently unknowingly?) your whole argument right there, because globals are bad and absolutely not project-specific and absolutely do cause compatibility issues between different Python projects
If you ever come around to Nix, it takes care of this problem for good (as in, it guarantees that you will never have 2 projects that step on each other), across every ecosystem, not just Python's. Unfortunately, I don't see very many Python projects at all that contain a flake.nix file, which is a damn shame, because it would cause people like me to hate Python just a tiny bit less
It used to be hard. A global site-packages or dist-packages dir is hard. Conda and all those tools make it worse.
A virtualenv is a directory. It contains a copy of Python and everything needed.
You don't even need to activate it. You can simply use the binaries that exist in those directories.
It's literally this simple:
$ python -m venv pmarreck
$ pmarreck/bin/python --version
Python 3.10.12
$ pmarreck/bin/pip install harlequin
Collecting harlequin
Downloading harlequin-1.8.0-py3-none-any.whl (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 kB 1.2 MB/s eta 0:00:00
...
Successfully installed MarkupSafe-2.1.3 click-8.1.7 duckdb-0.9.2 harlequin-1.8.0 jinja2-3.1.2 linkify-it-py-2.0.2 markdown-it-py-3.0.0 mdit-py-plugins-0.4.0 mdurl-0.1.2 numpy-1.26.3 platformdirs-3.11.0 prompt_toolkit-3.0.36 pyarrow-14.0.2 pygments-2.17.2 pyperclip-1.8.2 questionary-2.0.1 rich-13.7.0 rich-click-1.7.3 shandy-sqlfmt-0.21.1 textual-0.46.0 textual-fastdatatable-0.5.0 textual-textarea-0.9.5 tomli-2.0.1 tomlkit-0.12.3 tqdm-4.66.1 tree-sitter-0.20.4 tree_sitter_languages-1.9.1 typing-extensions-4.9.0 uc-micro-py-1.0.2 wcwidth-0.2.12
$ pmarreck/bin/harlequin
Boom, the tool launched immediately. No conflicts with anything else. When I am done, `rm -rf ~/pmarreck`, done.I did all of this in my home directory.
It literally cannot get easier than this.
Also, nobody active in the Python community will argue that there's 1 correct way to do packaging. That's a serious straw man.
Fortunately, none of those tools you mentioned other than venv are actually required to run Python applications, and there are in fact exactly 2 recommended ways to install Python applications:
1) Use your system's package manager
2) Use a venv, either manually (as shown in the sibling comment) or using the Pipx tool, which just creates venvs for you.
All of the other tools you mentioned (except for Pyenv) represent ~20 years of active development and iteration on how to manage projects and build packages for distribution, and end-users shouldn't even have to be aware of their existence. And Pyenv is just Rbenv but for Python.
As I've pointed out elsewhere, this is exactly the same situation as with literally every other programming language that doesn't generate standalone executables, and is even a problem with those that do, if they rely on dynamic linking. The special ire towards Python in this case is neither warranted nor valid.
Your pinned post on Twitter is predicated on double standards and lack of basic understanding of the tools you're criticizing. I'm not sure that's a good way to represent oneself.
If it means that I get to see less Python, then I guess... Mission accomplished? LOL
My first, second and tenth experiences with Python were all negative. Everything from trying to exit the REPL the first time I used it and getting chastised for doing it wrong (which meant that it knew what I was trying to do, and instead of just doing that, decided to be a little snit about it, which is about the jerkiest attitude a tool can take), to the Python 2.x->3.x transition pains, to the significant whitespace, to every project stepping on the dependencies of every other project (you might argue that "I just didn't use venv right" but I did follow every package's installation instructions!), to... Well, just read this, he did a good summary: https://medium.com/nerd-for-tech/python-is-a-bad-programming...
There's literally nothing I like about it. It just seems like a poorly written, older Ruby with a lot of baggage and a minefield of gotchas (except that I like Ruby... or did, before Elixir). Ruby should have absolutely fucking had Python's current market share, and I am 1000% convinced that if it did, everyone would be happier. Whenever Elixir tries to eat Python's lunch (like in the ML space which it's doing now), a part of me is as glad as a puppy. The language, despite its ubiquity, absolutely sucks in my mind, is not only a terrible introduction to programming for newbs but also likely an annoying language to work in, and the people who don't see it HAVE to be blind. That is the only conclusion I can come to, and I'm entitled to my opinion, strong as it is.
Next you're going to say that it is unprofessional to have such strong feelings about code and languages. To that I say: So what, dude. I care. Caring means having very positive feelings about the design decisions behind languages, or very negative feelings about the same. (I don't like Go, either. Python's basically a step above PHP on the "tech I want to minimize my time to zero with" department.)
If it's not hard then why is it not being done by default?
I am not a Python dev and I don't want to be, but when I have to install something via `pip` there's always pain.
"You could learn it", yeah yeah, Python is so special everyone has to learn it even if they don't ever work with it. How about learning from something modern like Go and Rust? `go install github.com/user/tool@latest`, boom, done. `cargo install the_tool`, boom, done.
Although your tool looks more like Virtualenvwrapper.
It's good to have other options of course (and yours looks nice), but it's also good to at least make a case for improvement over what's already out there.
I have, actually (though not Pipsi). Some others have commented on that and lead me to them.
Part of the "fun" of it was just doing it, I guess, and knowing exactly what went into it. Just a few lines of Bash, really.
It's like ye-olden days. Now we can go back to static linking and bundling everything in jar files and call it a win!
I suppose I could get around that by installing a Python interpreter outside of brew, and only use that for packages.
You can run pip in an isolated virtual environment, in user mode (not as root) - see https://gist.github.com/saurabhshri/46e4069164b87a708b39d947...
https://gist.github.com/saurabhshri/46e4069164b87a708b39d947...