Shell 脚本未正确安装 python3-pip

Shell 脚本未正确安装 python3-pip

我设置了一个脚本来为我正在开展的项目安装一堆东西,同时也为我安装我使用的 python 模块提供了一种简单的方法。当我运行这个脚本时,它确实准确地显示是否安装了 python3+,如果没有安装,它也会安装 python3。

它下载 portaudio 配置并构建它。它一直运行,直到我尝试安装 python 模块时失败。我得到的错误是

/usr/binpython3: No module named pip

如果我手动 sudo apt-get install python3-pip,它确实有效,如果我重新运行脚本,它确实会完成安装以下所有 python 模块。有人能告诉我为什么它没有正确安装 python3-pip 吗?还是因为它没有正确设置路径?有没有更好的方法可以做到这一点?

if [ $(id -u) = 0 ]; then
    echo "Do not run as root, yet. Try again."
    exit 1
fi

req=`python3 -c 'import sys; print("%i" % (sys.hexversion<0x03000000))'`
if [ $req -eq 0 ]; then
    echo 'python version is >= 3'
    echo 'Installing dependices'
    sudo apt-get install python3-pip libexpat1-dev libpython3-dev libpython3.5-dev python-pip-whl python3-dev python3-setuptools python3-wheel python3.5-dev build-essential git python3-dev ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev swig libpulse-dev python3-audio libasound-dev
    sudo apt-get update
else 
    echo "python version is < 3"
    echo "Installing Python3+ and dependencies" 
    sudo apt-get install python3 python3-pip libexpat1-dev libpython3-dev libpython3.5-dev python-pip-whl python3-dev python3-setuptools python3-wheel python3.5-dev build-essential git python3-dev ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev swig libpulse-dev python3-audio libasound-dev
    sudo apt-get update
    echo "Python 3 is now installed." 
fi 
read -p "Install remaining dependencies?(y/n)" ok
wget - http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz
tar -xvzf pa_stable_v190600_20161030.tgz
cd portaudio
echo n | ./configure && make
echo n | sudo make install
sudo apt-get update
echo n | sudo -H python3 -m pip install Cython==0.23 pyttsx3 chatterbot PyAudio PocketSphinx SpeechRecognition kivy==1.9.1
sudo -H python3 -m pip install bleach boto boto3 botocore bz2file cffi click colorama command-not-found cryptography cssselect decorator docutils fire flashtext Flask future gensim google-api-core google-api-python-client google-auth google-cloud-core google-cloud-storage google-resumable-media googleapis-common-protos html5lib httplib2 idna imbalanced-learn jedi Jinja2 jupyter jupyter-client jupyter-console jupyter-core kappa Keras  luminoth lxml nltk notebook numpy pandas pendulum Pillow pyasn1 pycrypto Pygments pygobject PyICU pymongo PyNaCl PyOpenGL PyQt5 PySDL2 pySFML python-dateutil python-twitter pytz PyYAML pyzmq qtconsole regex requestium requests rsa scikit-learn scipy selenium setuptools sip six SQLAlchemy ssh-import-id style tensorflow tensorflow-gpu tensorflow-tensorboard Theano tornado tqdm  urllib3 wheel xkit xlwt
if ! [ $ok = "y" -o $ok = "Y" ]; then exit 1

fi

答案1

您的 apt-get 命令可能在您没有注意到的情况下失败了。目前尚不清楚您使用的是哪个版本的 Ubuntu,但至少在 16.04 中,“python3-audio”包似乎不存在,导致命令失败。

尝试在脚本中输入正确的包名称(可能是“python3-pyaudio”)。

总体来说,它看起来像一个系统ansible而不是使用 shell 脚本会更适合你在这里做的事情。

相关内容