简体   繁体   中英

Activate python environment in chroot

I need to run commands in a Anaconda Python environment in a chroot with a bash script like this:

# install miniconda
chroot $chroot_path /bin/bash /miniconda.sh -f -b -p /miniconda

# Install packages in py2 environment
chroot $chroot_path /bin/bash source /miniconda/bin/activate py2 && /miniconda/bin/conda install notebook ipykernel

But I get:

/bin/bash: source: No such file or directory

How do I make it work?

There are two problems with this command

chroot $chroot_path /bin/bash source /miniconda/bin/activate py2 && /miniconda/bin/conda install notebook ipykernel

First, source is a bash keyword, not an executable program. When you do /bin/bash source /miniconda/bin/activate py2 you are trying to run a non-existent executable, which fails. Second, the part after the && will only run after the chroot has been exited. Instead you can use -c to run the line as a script

chroot $chroot_path /bin/bash -c "source /miniconda/bin/activate py2;/miniconda/bin/conda install notebook ipykernel"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM