pipenv is a tool that easily and automatically manages packages for the project and builds a virtual environment. It's a very convenient one that also works with pyenv.
When I ran it, an error occurred, so I put it in with pip, but it just didn't enter the virtual environment ...
I do a lot.
~/.bash_autopipenv
#!/bin/bash
function ispipenv()
{
if [ "$PIPENV_ACTIVE" == 1 ]; then
:
else
if [ -e "Pipfile" ]; then
pipenv shell
fi
fi
}
function pipenv_cd()
{
\cd $@ && ispipenv
}
alias cd='pipenv_cd'
The points are the following parts.
if [ "$PIPENV_ACTIVE" == 1 ]; then
...
When you enter the virtual environment, you are using the environment variable PIPENV_ACTIVE to be defined. Since PIPENV_ACTIVE is not defined if you are not in the virtual environment, it is evaluated with "$ PIPENV_ACTIVE" to avoid errors. Now the pipenv shell will not run when you are in the virtual environment.
Also, if \ cd in pipenv_cd is changed to cd, Note that pipenv_cd is called in pipenv_cd and pipenv_cd is called in it.
If you add the following to .bash_profile or .bashrc, it will always be read, so you will not forget to run pipenv shell: ok_hand:
if [ -f ~/.bash_autopipenv ]; then
. ~/.bash_autopipenv
fi
--Fun to create your own bash with shellscript: innocent: ――Next, don't forget to exit!
Recommended Posts