Score:0

How to automatically activate a python environment when 'source' command does not work?

vn flag

I set up an python environment in path \pyenv\1st\ by

cd /
mkdir pyenv
python3 -m venv /pyenv/1st

The official method to activate this environment is to type this command manually:

. /pyenv/1st/bin/activate or source /pyenv/1st/bin/activate,

which will result in (1st) in front of prompt and load corresponding python libraries.

I want to save typing and put this command in a file mypy, but sh mypy won't change the current terminal to the 1st python environment as I manually type that command. Add that command to \etc\bashrc won't help either. I heard that the source command will end in the subprocess like sh mypy but won't affect the terminal at all.

Can anyone solve this problem? Either a simple command or automatically load that environment as I open a terminal will help. Thanks in advance.

Score:0
in flag

just like you have to source the activate script to activate it, you need to do the same with the script calling it.

. ./mypy
George Y avatar
vn flag
I have already executed `sh mypy`, or `\bin\bash mypy` to be exact.
in flag
`sh mypy` is not the same as `source mypy`.
George Y avatar
vn flag
Thanks. I also tried add the command to the file `\etc\profile` and it also works.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.