Reputation: 191
I'm writing a bash script that automates the process of creating a django project and creating some folders and files that is necessary for a django project.
The problem here is, when I create and activate the virtual environment using the pipenv shell
command, The virtual environment is created and activated but the next command is not executed. The script just waits to exit the virtual environment and when I exit/deactivate the virtual environment, then the next lines of the bash script gets executed.
My next line is pipenv install django
. When this line is executed, django is installed in the virtual environment and again it waits for the user to exit the virtual environment and when I exit the environment, the next line is executed. But my next line is django-admin startproject myproject
when this line is executed, I'm getting the error command not found
. Yes I know why I'm getting this error. The environment is deactivated and it can't recognize the django-admin
command.
Also, I'm running this script as a superuser.
I'm using wsl2
.
my code:
mkdir "django_project"
cd "django_project"
pipenv shell
pipenv install django
read -p "Enter your project name: " PROJECT_NAME
django-admin startproject "$PROJECT_NAME"
cd "$PROJECT_NAME"
pipenv lock -r > requirements.txt
Once I run this script, I get this in the command line,
Creating a Pipfile for this project...
Launching subshell in virtual environment...
root@LENOVO:/home/ubuntu/USER/Bash_Projects/test_folder/django_project# . /root/.local/share/virtualenvs/django_project-IyKPiglU/bin/activate
(django_project) root@LENOVO:/home/ubuntu/USER/Bash_Projects/test_folder/django_project# exit
exit
Installing django...
Adding django to Pipfile's [packages]...
ā Installation Succeeded
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
ā Success!
Updated Pipfile.lock (a6086c)!
Installing dependencies from Pipfile.lock (a6086c)...
š āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā 0/0 ā 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
Enter your project name: test_project1
create_django_project.sh: line 6: django-admin: command not found
create_django_project.sh: line 7: cd: test_project1: No such file or directory
After this I terminated the script with ^C
The Pipfile is created successfully. The requirements.txt file is also created and all the packages are updated in the requirements.txt file.
My question is how to continue the script after activating the environment without deactivating it?
Upvotes: 0
Views: 317
Reputation: 11
I fixed this error by using just pip3
without pipenv
pip3 install django
in Super user mode use this command line
sudo -s
And it works for me My machine is UBUNTU 20.04 PYTHON VERSION 3.8.10
Upvotes: 1