summaryrefslogtreecommitdiff
path: root/compiler/one-cmds/one-prepare-venv
blob: e5c88411f23a238c616005bb84a763a158b89b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash

# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

VENV_ACTIVATE=${DRIVER_PATH}/venv/bin/activate

function error_no_ensurepip ()
{
  echo "ERROR: python3 'ensurepip' module is not found."
  echo "       On ubuntu, try following command:"
  echo
  echo "         apt install python$(python3 --version | awk '{print $2}' | awk -F. '{print $1"."$2}')-venv"
  echo
  echo "       You may need root privilege for this."
  exit 1
}

if [ ! -f ${VENV_ACTIVATE} ]; then
  # Install prerequisites
  python3 -m ensurepip --version > /dev/null 2>&1 || error_no_ensurepip
  python3 -m pip install --user -U virtualenv
  # Create python virtual enviornment
  python3 -m venv "${DRIVER_PATH}/venv"
fi

# Install tensorflow
source "${VENV_ACTIVATE}"

# TODO remove version number of 'pip==20.2.1 setuptools==49.3.0'
# NOTE adding version is for temporary hotfix of setuptools 50.x.y version
python -m pip --default-timeout=1000 --trusted-host pypi.org --trusted-host files.pythonhost.org \
  install -U pip==20.2.1 setuptools==49.3.0
python -m pip --default-timeout=1000 --trusted-host pypi.org --trusted-host files.pythonhost.org \
  install tensorflow-cpu==2.3.0
python -m pip --default-timeout=1000 --trusted-host pypi.org --trusted-host files.pythonhost.org \
  install Pillow==6.2.2

# Create python symoblic link
rm -f ${DRIVER_PATH}/python
ln -s venv/bin/python ${DRIVER_PATH}/python