What’s the problem this feature will solve?
Venv
and virtualenv
are both great tools. As an educator I prefer venv
, because it’s always with Python installation. Therefore this feedback is related to venv
.
I am using venv
everyday for last couple of years. I’ve been programming in Python since 2009 and recently I turned into teaching software engineering. This turn gave me a new perspective. Pretty often I teach people who first got into programming. Those classes are usually 15 people or more.
At the beginning of a training course I have to teach the following lines:
if you have windows, do:
python3.9 -m venv python-3.9.0
python-3.9.0/Scripts/activate.bat
but if you have Linux or macOS, than
python3.9 -m venv python-3.9.0
python-3.9.0\bin\activate
but if you have different shell than bash (fish, csh, etc. like macOS does).
and then…
Recently this is sent over email, before training course, which is even worse because people are with problems without trainer!
C’mon. Those people are afraid of terminal. Not mentioning:
- changing directory (each system has different paths, separators, permissions),
- there is a
-m venv
parameter which should have space before, inside and after, - they have to put some duplicate text (like
python3.9
andpython-3.9.0
) in a one line (why?!), - you have to explain how to check with Python version they have… (
python -v
andpython --version
produces completely different output
Sometimes I waste 30 minutes of training course to help people to setup and activate venv
!! This ruins the first impression and makes programming inaccessible. I wouldn’t dare, to recummend using venv
for a 3h hands-on workshop on a conference (because it will take so much time for explanation). Why, oh why you need to have different paths, activators and no reasonable defaults? In the other hand, if they start without venv
, and then install for example jupyter
with it’s all dependencies… it’s very messy, and it’s too for fixing it…
This makes using venv
hard for Python newcomers, and this is the reason why they prefer Anaconda.
I don’t think this is how we (Python community) should welcome newcomers, by advising to install bloated, 3rd party controlled (with customised settings [such as recursion limit, and whoever knows what else]).
Describe the solution you’d like
Creating and setting up venv
should be no-brainer one command, such as:
python -m venv --home --activate --install https://example.com/mycourse/requirements.txt
Let me explain (note, that all of this is backward compatible):
-
python3.9 -m venv
. If you haven’t specifiedvenv
directory it should by default create a new one with the namepython-3.9.0
(or your current Python version). Simple and backward compatible. -
A parameter like
python3.9 -m venv --home
should placevenv
inside~/.virtualenvs
directory (of course with default Python version name from example above). -
Currently, there is no
venv
default name. People are using a lot of different approaches:venv/
.venv/
_venv/virtualenv/
.virtualenv/
_virtualenv/py
python
py-3.9
python-3.9
python-3.9.0.py
.python
.py-3.9
.python-3.9
.python-3.9.0venv-3.6/
venv-3.7/
venv-3.8/
venv-3.9/
venv-3.10/venv-3.8.0/
venv-3.8.1/
venv-3.8.2/
venv-3.8.3/venv-3.9.0/
venv-3.9.1/
venv-3.9.2/
venv-3.9.3/venv-3.10-alpha1/
venv-3.10-alpha2/
venv-3.10-beta1/
venv-3.10-beta2/
venv-3.10-rc1/venv-django-2.1
venv-django-2.2
venv-django-2.3
venv-django-3.0
venv-django-3.1
venv-django-3.2
venv-django-4.0a1
venv-django-4.0a2
venv-django-4.0b1
venv-django-4.0b2
venv-django-4.0rc1
venv-django-4.0rc2venv-py39-dj33
venv-python39-django33
venv-python310alpha1-django40a1
Having standard name convention (and location) would help much with .gitignore
file, and prevent from committing those files into repository (it happens more often they you imagine).
-
--upgrade-deps
should be default without need to specify. Each time I’ve got questions like: why there is information about outdatedpip
after newly createdvenv
. If it knows it’s outdated, why it was not updated automatically. Which indeed is a very good question. And I also don’t understand why. (but this behaviour wouldn’t be backward compatible with current behaviour). -
The most important: activation. Current activators live in different paths
bin
orScripts
which is reflection of Python install directory and I understand why you did that on a developer level. But this should be hidden from end-user during activations! Why activation is not like:python-3.9.0/activate.py
(wherepython-3.9.0
isvenv
name). This script should recognise OS and Shell and use proper script. -
Activate on creation:
python3.9 -m venv --activate
. This would be handy. -
Install requirements on creation (This would solve so many problems):
python3.9 -m venv --install requirements.txt
python3.9 -m venv --install https://example.com/mycourse/requirements.txt
-
Of course it should be movable. From your OS you should drag-and-drop to some other location without having to recreate it and without breaking it. People does that, and they wonder why everything breaks.
-
Putting it all together:
python -m venv --home --activate --install https://example.com/mycourse/requirements.txt
- note, that python executable should be without version [a bit controversial for veterans, but for newcomers is a must]. And also it’s future proof.
I’ve seen countless python packages documentation with “Installation guides”: if you have windows do this… else do this… This makes venv
cumbersome for devs who want to share its software with quick installation guide. This makes using venv
hard for Python newcomers, and this is the reason why they prefer Anaconda. And I don’t believe it is a good way to go.
Imagine if you organise a training course or online course and you have to specify installation requirements.
Saying:
- Install newest Python from official website
- Open terminal (this sucks, but it’s a necessity).
- Run
python -m venv --home --activate --install https://example.com/mycourse/requirements.txt
- That’s it. You’re all set-up and ready to participate.
PS.
The last one is not directly related to venv
. IMHO venv
should allow other devs, such as Jupyter
(or Jupyter-lab
) to create a shortcut on a desktop after installation. This shortcut should activate venv
and run jupyter
. That would be a lifesaver!
PS2. I have created a GitHub issue at virtualenv
repository: