Reputation: 1
I am running this code while launching ec2 instance, python is installed, but the folder is not created.
#!/bin/bash
sudo yum update -y
sudo yum install python36 -y
mkdir venv
cd venv
virtualenv -p /usr/bin/pyton3.6 python36
echo "source /home/ec2-user/venv/python36/bin/activate" > /home/ec2-user/.bashrc
pip install boto3
Upvotes: 0
Views: 608
Reputation: 1
Thank you for inputs. This worked. Mainly:
'#!/bin/bash
sudo yum update -y
sudo yum install python36 -y
mkdir /home/ec2-user/venv
cd /home/ec2-user/venv
virtualenv -p /usr/bin/python3.6 python36
echo "source /home/ec2-user/venv/python36/bin/activate" >> /home/ec2-user/.bashrc
source /home/ec2-user/venv/python36/bin/activate
pip install boto3
Upvotes: 0
Reputation: 124648
A couple of things could go wrong with that script. I suggest a more robust way to write it:
#!/bin/bash
cd "$(dirname "$0")"
sudo yum update -y
sudo yum install python36 -y
if [ ! -d venv ]; then
mkdir venv
virtualenv -p /usr/bin/pyton3.6 venv/python36
echo "source venv/python36/bin/activate" >> ~/.bashrc
source venv/python36/bin/activate
pip install boto3
fi
Improved points:
cd
into the directory of the script~
~/.bashrc
if already existsboto3
, it's important to activate the virtual env, otherwise pip
will not install it inside the virtual env (it will try to install system-wide)Upvotes: 3