尽管可以手动逐行运行命令,但使用 shell 运行命令时出错

尽管可以手动逐行运行命令,但使用 shell 运行命令时出错

我在 vagrant virtualbox 上使用 centos7 RHEL,我正在制作一个 shell 文件,当我激活 vagrant 时,它会在虚拟操作系统上运行 shell 文件中的命令。

当我使用 SSH 并在 centos7 终端上运行每一行时,它可以工作,但是当我通过 shell 文件运行它时,它说没有名为 venv 的模块,而 venv 实际上已安装。我搞不懂,请帮忙。谢谢。

安装shell.sh

sudo yum update
sudo yum install epel-release -y
sudo yum install centos-release-scl -y
sudo yum install git wget ibxslt-devel bzip2-devel openldap-devel libjpeg-devel freetype-devel -y
sudo yum groupinstall 'Development Tools' -y
sudo useradd -m -U -r -d /opt/odoo -s /bin/bash odoo
sudo -i
sudo bash -c 'echo "odoo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers'

## Gist url
echo -e "\n---- "
export GIST_URL="https://gist.githubusercontent.com/Tarrasque18/c111670cb100b41bb6bf88064be9cc80/raw"

export PERL_UPDATE_ENV="perl -p -e 's/\{\{([^}]+)\}\}/defined \$ENV{\$1} ? \$ENV{\$1} : \$&/eg' "
 [[ -z $SYSTEM ]] && echo "Don't forget to define SYSTEM variable"

echo -e "\n---- Install Postpresql ----"
sudo yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sudo yum install -y postgresql11-server.x86_64 postgresql11-contrib.x86_64
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl start postgresql-11
sudo systemctl enable postgresql-11
# Create odoo user
sudo su - postgres -c "createuser -s odoo"
sudo su - postgres -c "createuser -s root"

echo -e "\n---- Install wkhtmltox ----"
sudo yum install -y https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm

echo -e "\n---- Install Python 3 ----"
sudo yum install -y centos-release-scl libxml2-devel libxslt-devel python-devel
sudo yum install -y rh-python36
scl enable rh-python36 bash

echo -e "\n---- Install Nginx ----"
cd /etc/yum.repos.d/
wget -q ${GIST_URL}/nginx.repo -O nginx.repo
sudo yum -y update
sudo yum install nginx -y
systemctl enable nginx
service start nginx

echo -e "\n---- Install Certbot ----"
sudo yum -y install yum-utils
sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
sudo yum -y install python2-certbot-nginx

echo -e "\n---- Install Odoo ----"
sudo yum –y update
cd /opt/odoo  
git clone https://www.github.com/odoo/odoo --depth 1 --branch 12.0 /opt/odoo/odoo

echo -e "\n---- Upgrade pip ----"
scl enable rh-python36 bash
cd /opt/odoo
python -m venv --without-pip odoo-venv
source odoo-venv/bin/activate
pip install --upgrade pip
pip install wheel
cd /opt/odoo
pip install -r odoo/requirements.txt
deactivate
mkdir /opt/odoo/odoo-custom-addons
sudo chown odoo: /opt/odoo/odoo-custom-addons

echo -e "\n---- Odoo config ----"
sudo yum -y install moreutils
cd /etc/
sudo wget -q ${GIST_URL}/odoo.conf -O odoo.conf
eval "${PERL_UPDATE_ENV} < odoo.conf" | sponge odoo.conf

echo -e "\n---- Install and enable odoo service ----"
cd /etc/systemd/system/
sudo wget -q ${GIST_URL}/odoo.service -O odoo.service
systemctl daemon-reload
systemctl start odoo
systemctl enable odoo
# Set enforce
setenforce 0

echo -e "\n---- Config nginx ----"
cd /etc/nginx/conf.d/
sudo wget -q ${GIST_URL}/nginx-odoo.conf -O odoo.conf
eval "${PERL_UPDATE_ENV} < odoo.conf" | sponge odoo.conf

systemctl restart nginx

答案1

既然您安装了 python 3.6,为什么还要使用“python -m venv”而不是“pyvenv3 -m venv”。CMIIW。

我从这里读到: https://developers.redhat.com/blog/2018/08/13/install-python3-rhel/ https://realpython.com/installing-python/

相关内容