Python Forum
Python related simple shell scripting issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python related simple shell scripting issue
#1
I have a whole bunch of old projects that were created without virtual environment.
many of them use the same packages, so I thought I'd create a bash script to:
  1. Create a virtual environment
  2. Activate the environment
  3. Create a requirements.txt file for the packages
  4. Run pip to install the packages
  5. deactivate the virtual environment
  6. Move to next project and do it all again

Everything works until I get to step 5 (deactivate) The command executes, but when the script exits, the virtual environment is still running
My bash shell programming skills are very rusty, so what am I doing wrong?

script:
#!/bin/bash
python -m venv venv
. ./venv/bin/activate
cat > ./venv/requirements.txt << EOM
lxml
requests
pylint
BeautifulSoup4
selenium
EOM
pip install -r ./venv/requirements.txt
cp -r ../../../A-D/D/drivers/chromedriver ./venv/bin/chromedriver
cp -r ../../../A-D/D/drivers/geckodriver  ./venv/bin/geckodriver
. deactivate
Reply
#2
Maybe just instead of:
. deactivate
try:
deactivate
Reply
#3
That works fine.
Thank You!
Reply
#4
I guess deactivate is created as alias.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
It is, when executing activate
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020