Skip to content

Commit 34aab64

Browse files
ddecrulleavouacr
andauthored
fix(python): use prefix to install Python in separate location from ubuntu's system version (#295)
* use prefix for python installation and add `LD_LIBRARY_PATH` env * update * add symlink * add registry * add symplink for retrocompatibility * remove registry * fix test * trim * retro-compat * install in opt/python * fix tests --------- Co-authored-by: avouacr <[email protected]>
1 parent a47e204 commit 34aab64

File tree

18 files changed

+71
-56
lines changed

18 files changed

+71
-56
lines changed

base/scripts/fix-user-permissions.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ set -e
33

44
# Chown only if needed to avoid duplicate files in Docker layers
55

6-
# Give user permission on all files in HOME
76
find "${HOME}" -not -user "${USERNAME}" -execdir chown --no-dereference "${USERNAME}:${GROUPNAME}" {} \+
8-
7+
find "/opt/" -not -user "${USERNAME}" -execdir chown --no-dereference "${USERNAME}:${GROUPNAME}" {} \+
98
# Give user permissions on all files in /usr/local except cuda folders
109
find /usr/local/ \( -path "/usr/local/cuda*" -prune \) -o \
1110
\( -not -user "${USERNAME}" -execdir chown --no-dereference "${USERNAME}:${GROUPNAME}" {} + \)

base/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"

jupyter/tests.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fileExistenceTests:
1414
path: "/opt/onyxia-init.sh"
1515
shouldExist: true
1616
permissions: "-rwxr-xr-x"
17-
uid: 0
18-
gid: 0
17+
uid: 1000
18+
gid: 100
1919
commandTests:
2020
- name: "Does the binary exists?"
2121
command: "which"
@@ -29,10 +29,18 @@ commandTests:
2929
command: "which"
3030
args: ["mc"]
3131
expectedOutput: ["/usr/local/bin/mc"]
32+
- name: "Does the binary exists?"
33+
command: "which"
34+
args: ["python"]
35+
expectedOutput: ['/opt/python/bin/python']
36+
- name: "Does the binary exists?"
37+
command: "which"
38+
args: ["pip"]
39+
expectedOutput: ['/opt/python/bin/pip']
3240
- name: "Does the binary exists?"
3341
command: "which"
3442
args: ["jupyter-lab"]
35-
expectedOutput: ["/usr/local/bin/jupyter-lab"]
43+
expectedOutput: ["/opt/python/bin/jupyter-lab"]
3644
- name: "Does the binary exists?"
3745
command: "which"
3846
args: ["duckdb"]

python-datascience/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"
@@ -31,11 +31,11 @@ commandTests:
3131
- name: "Does the binary exists?"
3232
command: "which"
3333
args: ["python"]
34-
expectedOutput: ["/usr/local/bin/python"]
34+
expectedOutput: ['/opt/python/bin/python']
3535
- name: "Does the binary exists?"
3636
command: "which"
3737
args: ["pip"]
38-
expectedOutput: ["/usr/local/bin/pip"]
38+
expectedOutput: ['/opt/python/bin/pip']
3939
- name: "Does the binary exists?"
4040
command: "which"
4141
args: ["quarto"]

python-minimal/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ LABEL maintainer="InseeFrLab <[email protected]>"
66
ARG PYTHON_VERSION="3.13.5"
77
ENV PYTHON_VERSION=${PYTHON_VERSION}
88

9-
# Ensure local Python is preferred over system version
10-
ENV PATH="/usr/local/bin:${PATH}"
9+
# Install Python separately from system installation to avoid conflicts
10+
ARG PYTHON_DIR="/opt/python"
11+
ENV PATH="${PYTHON_DIR}/bin:${PATH}"
1112

1213
USER root
1314

python-minimal/scripts/install-python.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,19 @@ apt_install \
2929
xz-utils \
3030
zlib1g-dev
3131

32-
# Install Python
32+
# Build Python from sources
3333
wget -q https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
3434
tar xzvf Python-${PYTHON_VERSION}.tgz
3535
cd Python-${PYTHON_VERSION}
3636
./configure \
37-
--enable-loadable-sqlite-extensions \
38-
--enable-optimizations \
39-
--enable-shared \
40-
--with-lto
41-
make -j4
37+
--prefix="${PYTHON_DIR}" \
38+
--enable-loadable-sqlite-extensions \
39+
--enable-optimizations \
40+
--enable-shared \
41+
--with-lto \
42+
LDFLAGS="-Wl,-rpath ${PYTHON_DIR}/lib"
43+
make -j"$(nproc)"
4244
make install
43-
ldconfig
44-
45-
# Useful symlinks
46-
ln -s /usr/local/bin/python3 /usr/local/bin/python
47-
ln -s /usr/local/bin/pip3 /usr/local/bin/pip
48-
49-
# Checks
50-
python --version
5145

5246
# Clean install files
5347
cd ..
@@ -56,6 +50,14 @@ apt-mark auto '.*' > /dev/null
5650
apt-mark manual $savedAptMark
5751
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
5852

59-
# Upgrade pip & install uv for further Python packages installation
53+
# Useful symlinks
54+
ln -sf "${PYTHON_DIR}/bin/python3" "${PYTHON_DIR}/bin/python"
55+
ln -sf "${PYTHON_DIR}/bin/pip3" "${PYTHON_DIR}/bin/pip"
56+
57+
# Checks
58+
python --version
59+
which python
60+
61+
# Upgrade pip & install uv
6062
pip install --no-cache-dir --upgrade pip
6163
pip install --no-cache-dir uv

python-minimal/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"
@@ -31,11 +31,11 @@ commandTests:
3131
- name: "Does the binary exists?"
3232
command: "which"
3333
args: ["python"]
34-
expectedOutput: ["/usr/local/bin/python"]
34+
expectedOutput: ['/opt/python/bin/python']
3535
- name: "Does the binary exists?"
3636
command: "which"
3737
args: ["pip"]
38-
expectedOutput: ["/usr/local/bin/pip"]
38+
expectedOutput: ['/opt/python/bin/pip']
3939
- name: "Does the binary exists?"
4040
command: "which"
4141
args: ["duckdb"]

python-pytorch/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"
@@ -31,11 +31,11 @@ commandTests:
3131
- name: "Does the binary exists?"
3232
command: "which"
3333
args: ["python"]
34-
expectedOutput: ["/usr/local/bin/python"]
34+
expectedOutput: ['/opt/python/bin/python']
3535
- name: "Does the binary exists?"
3636
command: "which"
3737
args: ["pip"]
38-
expectedOutput: ["/usr/local/bin/pip"]
38+
expectedOutput: ['/opt/python/bin/pip']
3939
- name: "Does the binary exists?"
4040
command: "which"
4141
args: ["duckdb"]

python-tensorflow/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"
@@ -31,11 +31,11 @@ commandTests:
3131
- name: "Does the binary exists?"
3232
command: "which"
3333
args: ["python"]
34-
expectedOutput: ["/usr/local/bin/python"]
34+
expectedOutput: ['/opt/python/bin/python']
3535
- name: "Does the binary exists?"
3636
command: "which"
3737
args: ["pip"]
38-
expectedOutput: ["/usr/local/bin/pip"]
38+
expectedOutput: ['/opt/python/bin/pip']
3939
- name: "Does the binary exists?"
4040
command: "which"
4141
args: ["duckdb"]

r-datascience/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fileExistenceTests:
1313
path: "/opt/onyxia-init.sh"
1414
shouldExist: true
1515
permissions: "-rwxr-xr-x"
16-
uid: 0
17-
gid: 0
16+
uid: 1000
17+
gid: 100
1818
commandTests:
1919
- name: "Does the binary exists?"
2020
command: "which"

0 commit comments

Comments
 (0)