3 ms·
This is great advice. To tack on: Python has had built-in virtualenv support since 3.3[1], meaning that you can do this: python -m venv env/ ...on any ve
by woodruffw 4y ago
This is great advice. To tack on:
Python has had built-in virtualenv support since 3.3[1], meaning that you can do this:
python -m venv env/
...on any version of Python released in the last decade and get a reasonable virtual environment. To go one step further, you can also have `venv` automatically bring `pip` and `setuptools` to their latest versions:
python -m venv --upgrade-deps env/
...which you should almost always do, since the versions bundled with your Python distribution are likely to be behind the latest.
- jonatron 4y agoIf you're on Debian/Ubuntu, you'd first need to install python3-virtualenv. It does say that though IIRC, if you try without it installed.
- deleted 4y ago[deleted]
- woodruffw 4y agoAlmost! `python3-virtualenv` is virtualenv, the third-party tool that ultimately inspired `venv`. `python3-venv` is the Ubuntu/Debian breakout package for `python -m venv`. TL;DR: Install python3-venv, not python3-virtualenv. (Ubuntu and Debian's decision to break out core parts of the Python standard library has been an unending source of problems. PEP 668[1] is an in-progress effort to better categorize these kinds of distro changes and improve the user experience around them.) Edit: I should also qualify: virtualenv is still maintained and useful; venv is contains the subset of virtualenv's functionality that 99% of users use. [1]: https://peps.python.org/pep-0668/ https://peps.python.org/pep-0668/
- CobrastanJorji 4y agoYeah, I strongly advise ALWAYS using a virtualenv for any Python project. It's pretty much always a good idea.
- srvmshr 4y agoAs someone who uses environment & containers fairly regularly, to this day, I didn't know `virtualenv` & `venv` were actually two different packages. I always used these interchangeably. I saw the difference pointed out in the article.
- gernb 4y agoand how am I able to run python -m venv env/ if haven't already installed python? with node I use nvm. No root need, have never run into a problem of something complaining that I don't have node installed at a system level. Is there an equivalent for python?
- Chiron1991 4y agopyenv. same thing as nvm, but for Python.
- jeroenhd 4y agoHow am I able to run npm install/nvm install if I haven't already installed Node? I've seen way more machines that come with Python than I've seen machines that come with Node. You need to install and configure nvm, just like you need to install and configure Python. The difference is that pip comes from a time when package managers were still universally global, while npm and friends only operate on directories by default. If you want a systemless Python then you'll have to do it manually. I don't think it happens often enough for it to have a tool like nvm. Nothing prevents you from downloading the binaries, stuffing them into your user folder and setting up the right environment variables in your .profile, except for that it's a pain and probably not worth the effort. Edit: apparently pyenv is a thing. I haven't ever needed it myself, but it seems to do everything nvm does and more. If you just want to restrict package installs, versions, and configurations to a single project, virtual envs are the way to go.