I'm trying to make bash script which should activte my python virtualenv I have it like that:
#!/bin/bash
source /home/xnicram/python/AMW/env/bin/activate
Why it's not working? When I write same in consloe then it;s working
I'm trying to make bash script which should activte my python virtualenv I have it like that:
#!/bin/bash
source /home/xnicram/python/AMW/env/bin/activate
Why it's not working? When I write same in consloe then it;s working
Copyright © 2021 Jogjafile Inc.
When you run the script, the shell starts a new process for it. The script does activate the venv, and then the script process exits, and with that all its settings, like those done by the venv's activation script, are lost. You're back to the parent process, and everything is as before calling the script. When you run it manually on the console, you stay in the same shell (same process), so the settings stick.
To start the venv in a script, you can make a shell function:
and then call
set_python_envin script or shell.You can even go a step further and hook into the
cdcommand and have it check whether youcdinto or out of a pyenv and then activate or deactivate the environment. Put this into e.g., your~/.bashrc:Adjust the
envvariable to your preferred Python environment folder name.