-1

Almost every day I have to start my django project. So the sequence of commands that are used:

cd myProject
source venv/bin/activate
cd djangoproject
python3 manage.py runserver

I have put these commands to start.txt file. But bash start.txt doesn't start virtualenv. Am i doing something wrong?

phd
  • 82,685
  • 13
  • 120
  • 165
Naur
  • 81
  • 7

2 Answers2

0

I have function like this in my .bashrc..

function cds() {
        cd $1; ls -lart

        current_dir=$PWD
        venv_dir="$current_dir/venv"
        if [ -d $venv_dir ];
        then
                venv_activate="$venv_dir/bin/activate"
                echo "Directory has corresponding virtual environment.."
                echo "Sourcing $venv_activate.."
                source $venv_activate
        else
                deactivate
        fi
}

If you're going to use bash file, you should add /bin/bash on the topmost part of the file and file extension should be .sh

to run this, update your .bashrc and then

$ source ~/.bashrc
$ cds ~/dev/my_project

It will go to you directory, list the files, and activate virtual env

Ron Marcelino
  • 463
  • 3
  • 8
-1

You'll want to put this in a .sh file, then use chmod +x to make it executable. For example:

echo pwd > myscript.sh
chmod +x myscript.sh
./myscript.sh

Additionally, you can add this to the bin file on your machine to avoid having to run it from the relative path every time. Google where your bash commands are for your distro if you want to do this too!

  • Made like you said, situation hasn't changed. Virtual environment is still inactive – Naur Nov 13 '19 at 03:19