转自:https://labdmitriy.github.io/blog/poetry-installation-offline/
MotivationPermalink
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.
AssumptionsPermalink
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 internetPermalink
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 internetPermalink
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
ConclusionPermalink
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 scriptsPermalink
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
以下为遇到的问题
换源
临时:
pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
安装的依赖:
在离线环境install时遇到依赖三方包没有的问题
*ERROR: Could not find a version that satisfies the requirement dulwich<0.22.0,>=0.21.2 (from poetry) (from versions: none)
ERROR: No matching distribution found for dulwich<0.22.0,>=0.21.2*
pip3 download xxx
backports.cached_property=>dulwich=》setuptools=>wheel=>msgpack=>Cython=>rapidfuzz
(pip3 download rapidfuzz==2.15.1)
依赖包不符合=》给改成了none-any.whl就可以了。