You are not logged in.
Pages: 1
I want a way to enable the automatic source of the virtual enviroment of python after it has been created by the user
Last edited by gaming (2024-11-16 08:30:03)
Offline
Huh?
Do you just want a shell function that combines the creation and activation steps? If so, then add the function to your shellrc. I'm really not clear at what level you're asking this question. Can you give a use-case for how you would like the results of this goal to work?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
You can just chain the commands to create the venv and activate it if you want to be able to do this as a single operation:
python -m venv /path/to/venv && source /path/to/venv/bin/activate
Offline
Well thank you for replies
I am asking a way or command that will automatically source a already created python venv, so we don't have to source it every time we want to use pip
Offline
What do you mean by "automatically"?? You say you want a command to source an existing env (that command is source), but you want to be able to source it without having to source it? What does that even mean?
Again, what do you actually want to do?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Hi
If you want to activate virtualenv automatically when you enter specific directory there are few possibilities
Option A
You can install direnv https://direnv.net/
In configuration file ~/.direnvrc add
layout_virtualenv() {
local venv_path="$1"
source ${venv_path}/bin/activate
}
In your directory create file .envrc with content:
layout_virtualenv /path/to/your/venv
And call direnv allow
Now every time you enter this directory virtualenv will be activated.
Option B
Use pyenv to maintain python version https://github.com/pyenv/pyenv
Install pyenv-virtualenv plugin https://github.com/pyenv/pyenv-virtualenv
To create virtualenv call pyenv virtualenv <python version> <virtualenv name>.
To activate virtualenv in current directory pyenv local <virtualenv name - this will create file .python-version containing your virtualenv name. Every time you will enter this directory you virtualenv will be activated.
Offline
You don't have to source the venv to use pip:
$ python -m venv .venv
$ .venv/bin/pip install whatever
uv offers a much faster and better way anyhow. This is equivalent to above:
$ uv venv
$ uv pip install whatever
Offline
I have found another way a package called pipenv
https://github.com/pypa/pipenv
Last edited by gaming (2024-11-01 05:51:17)
Offline
Pages: 1