And how do I do that from inside an already running Emacs session? (Or Vscode?)
Needing to "prepare" an environment before you can work with it, prevents you from simply "jumping" into a task from an existing workflow.
Working with .NET, Rust, Node, go, Haskell, etc... I have no such issues.
This "venv"-requirement only applies to Python, and it's really the opposite of ergonomic. I really think it's about time the Python-community starts recognizing this.
Instead, I recommend just running the other executables in the bin directory. `./bin/python` will drop you into a Python REPL with all the packages installed in that virtualenv available. Your IDE should let you specify what Python interpreter to use for running tests and other integrations; give it the path to that Python executable and everything should Just Work. Likewise, if your package uses setuptools entrypoints, they'll be installed into the bin directory too, and you can just run them with no further configuration.
For what it's worth, Rust (for one) works pretty much the same way. The only difference is that Rust doesn't have a concept of dependencies installed system-wide, they're always handled per-project like venvs. As a result, they don't have decades of stale tutorials online telling people to do the wrong thing.
Now that I'm used to the subshell idea, I use the same concept across ruby, node, and python; it's almost always a better fit than what the usual packaging tools give you. I don't need `bundle exec` in ruby, for instance.
Respective solutions: NuGet, cargo, npm, go get, cabal. They all solve pretty much the same issue as venv and prepare your project in pretty much the same way. Raw venv can be a bit rough, but poetry solves that.
From VSCode I just use the integrated terminal to create the venv, vscode's default python extensions recognizes in-process venvs by default and uses them. (The way it installs tooling is broken for them, though, but that's a bug in the extension.)
Though it would be nice if Code integrated poetry so that just having a poetry-compatible pyproject.toml was sufficient.
> Working with .NET, Rust, Node, go, Haskell, etc... I have no such issues.
For most of those (Haskell with Cabal included), they have the same basic issue and solve it with a project file which is pretty similar in purpose and effect to poetry’s use of pyproject.toml.
Node definitely has this issue. There's a reason Node NVM[1] exists.
M-x pyvenv-activate
Or in your init: (pyvenv-activate "~/code/python/venv_dir/emacs_venv")
VSC: C-P
Python: select interpreter
It's pretty simple, and claiming nuget, node, and cabal/stack as superior means you're either lucky or inexperienced.Remembering to start/stop virtualenv and remembering the names of your virtual envs is one too many steps
The issue here is, that you are not storing hashsums and therefire are not safe.
To store hashsums you need a frozen requirements file, which needs another puthon lib … at this point it might be easier to use Poetry or Pipenv.
Pyenv is not unlike nvm for Node. Python moves too fast to expect the OS distributions to keep up.
From a stability, reliability, and CI/CD performance standpoint, I would discourage building your own Python. Things break more the more often your base version changes.
You'll be required to install a ton of apt system dependencies, then add a custom system apt package index (ppa), then install it from the new repository and hope you managed to get all required dependencies. I failed several times in a row last time before I got it working, after trying 2 different methods.
- Python -m venv + ./bin/activate + pip
- poetry
- pipenv
- pip (without isolation of projects)
You may add varying recommandations on the usage of OS python or a user installed one, but I think the same concern exists with most languages.
The main problem is that Python's mantra is supposed to be "There is only one way to do it". Less than two years ago, I read the official PEP doc about "Managing Application Dependencies", and it was a mess. pipenv was recommended (and still is), but there was a critical bug that ended in fatal errors on my development system.
Basically, start with "pip (without isolation of projects)" until it doesn't work for you because of library version clashes, then move to either pipenv or "Python -m venv + ./bin/activate + pip" (which are basically the same thing).
Poetry isn't as widely used.