'batch: launch pipenv shell, then run command in the virtual environment
Here is a batch script:
Z:
cd Z:\different_directory
pipenv shell
cd ..\another_directory
:End
cmd /k
What happens here is that the pipenv shell gets launched, but the virtual environment does not cd. Instead, once I exit the pipenv, it then runs the cd command.
Is it possible to run a command from inside the pipenv using this batch script?
Solution 1:[1]
You can use pipenv run instead of pipenv shell to directly run a python command or a batch script. You won't be able to run pipenv run cd ../another_dir directly, but I'm assuming that isn't the main goal of this since you'd only be changing the directory in that session. You can create a batch script, say test.bat, with
cd ../another_dir
python test.py
Then run it with pipenv run test.bat. The page below has more details.
source: http://witkowskibartosz.com/blog/pipenv_run_vs_pipenv_shell.html#.W2SBZflKhaQ
Solution 2:[2]
I know this question is old but if any of you found this through google, here's the exact answer: Just use pipenv shell "/c command [args]", in this case pipenv shell "/c cd ..\another_directory"
Why this works: Like the documentation says, whatever comes after shell will be passed as an argument to the subshell, and the argument /c on CMD runs a command on shell spawn. So there. You could even make it run a whole .bat.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Raff.run |
