1 minute read

Motivation

What if you are using Poetry and due to some restrictions should install it on machine without internet?

After searching for the existing solutions, I only found GitHub issues like that with the same questions but without exact answers, so I decided to research it myself.

Finally I found pipeline for installing poetry offline with new installer for the current Poetry implementation.

Assumptions

Let’s assume for the next steps that:

  • For the installation we choose poetry version 1.1.13
  • Ubuntu 20.04 is used
  • Python is installed
  • Source and destination directories are located in /tmp/poetry_dist

Machine with internet

Create and navigate to the directory where distribution will be prepared:

cd /tmp && mkdir poetry_dist && cd poetry_dist

Choose poetry version required for installation.
You can easily check which poetry versions are available for pip >= 21.2 (for older versions you can find corresponding method here):

pip index versions poetry

Save current installation code to the local file:

curl -o poetry_install.py -sSL https://install.python-poetry.org

Modify code to use local folder with wheels to install (Poetry and its dependencies):

sed -i 's/"install", specification/"install", "--no-index", "--find-links=.", specification/g' poetry_install.py

Select version and download all required packages:

env VERSION=1.1.13 bash -c 'pip download poetry==$VERSION'

Archive required files:

tar -czvf poetry_dist.tar.gz poetry_install.py *.whl --remove-files

Copy archive to the machine without internet to the destination folder:

/tmp/poetry_dist

Machine without internet

Navigate to the directory where distribution archive is located:

cd /tmp/poetry_dist

Extract archive:

tar -xzvf poetry_dist.tar.gz

Uninstall existing version of poetry (if any):

python poetry_install.py --uninstall

Install poetry from local file:

env VERSION=1.1.13 bash -c 'python poetry_install.py --path $(ls poetry-$VERSION*.whl)'

Delete intermediate files

rm poetry_install.py *.whl

Check that installation was successful

poetry --version

Conclusion

Probably it will be great to be able to pass pip arguments to install_poetry() function to reproduce these steps without installation code modification.

Shell scripts

Also I created shell scripts in repository to automate these steps:

poetry_dist_prepare.sh
Prepare distribution for specific Poetry version in /tmp/poetry_dist folder.
Usage example (on machine with internet):

./poetry_dist_prepare.sh 1.1.13


poetry_dist_install.sh
Extract distribution archive located in /tmp/poetry_dist folder and install Poetry offline. Usage example (on machine without internet):

./poetry_dist_install.sh 1.1.13

Comments