Что делать если нужно поставить какую-то Python-библиотеку а root-прав нет? То есть в систему библиотеку никак и ничего не поставить.
Есть как минимум два способа это решить правильно!
🔸 Сделать виртуальное окружение и ставить там что угодно.
Это позволит создать полностью независимое исполняемое окружение для ваших приложений.
Все библиотеки будут храниться в домашней директории юзера а значит доступ на запись имеется.
Создать очень просто:
python3 -m venv ~/venvs/myenvname
Теперь активируем окружение
# Linux
source ~/venvs/myenvname/bin/activate
# Windows
%userprofile%\venvs\myenvname\Scripts\activate.bat
Можно ставить любые библиотеки и запускать приложение.
Это стандартный метод работы с любым проектом. Если еще не используете его, то пора начинать. Даже при наличии root доступа!
🔸 Бывает, что нет возможности запустить приложение из своего виртуального окружения. Например, его запускает какой-то сервис от вашего юзера и вставить активацию окружения вы не можете.
В этом случае можно установить библиотеки для Python не глобально в систему, а только для юзера.
Выполните этот код в консоли:
python3 -m site
Вы получите что-то такое:
sys.path = [
'/home/user',
'/usr/lib/python37.zip',
'/usr/lib/python3.7',
'/usr/lib/python3.7/lib-dynload',
'/home/user/.local/lib/python3.7/site-packages',
...
]
USER_BASE: '/home/user/.local'
USER_SITE: '/home/user/.local/lib/python3.7/site-packages'
ENABLE_USER_SITE: True
Нас интересует параметр USER_SITE. Это путь к пользовательским библиотекам, которые доступны по умолчанию, если они есть.
Именно сюда будут устанавливаться модули если добавить флаг --user при установке чего-либо через pip
pip install --user requests
Для этой команды не нужны root-права.
После неё можно запускать системный интерпретатор без виртуальных окружений и установленная библиотека будет доступна для текущего юзера.
Параметр USER_BASE показывает корневую директорию для хранения user-библиотек. Её можно изменить с помощью переменной окружения PYTHONUSERBASE
export PYTHONUSERBASE=~/pylibs
python3 -m site
...
USER_BASE: '/home/user/pylibs'
USER_SITE: '/home/user/pylibs/lib/python3.7/site-packages'
Получается некоторое подобие виртуального окружения для бедных 😁 которое можно менять через эту переменную (не делайте так!Лучше venv!)
🔸 Дописывание пути в PYTHONPATH
Этот способ не входит в список "двух правильных", но тоже рабочий. Здесь придётся сделать всё несколько сложней.
Сначала ставим библиотеку в любое место указывая путь установки
pip3 install -t ~/mylibs modulename
Библиотека установится без привязки к какому-либо интерпретатору. То есть по умолчанию не будет видна. Теперь в нужный момент добавляем этот путь в sys.path или в PYTHONPATH.
Не буду советовать так делать. Единственный раз когда этот способ мне пригодился и решил поставленную задачу, это при создании общей библиотеки для кластера компьютеров.
Модули лежат в сети и подгружаются для всех из одного и того же места. То есть обновлять файлы требуется только один раз а не на всех хосты отдельно.
Минусы такого подхода:
▫️Нужно всем хостам пробить нужный путь в .bashrc или ещё куда-то чтобы он сетапился на старте.
▫️Чем больше хостов тем больше нагрузка на сеть. Иногда такой способ не подходит именно по этой причине. Тогда Ansible вам в помощь.
▫️Не очень подходит если хосты с разными операционками. Некоторые библиотеки различаются для Linux и Windows (там, где есть бинарники) и приходится мудрить более сложные схемы.
#tricks#basic
Let’s bring the Dogs Data to TikTok
Join the 🐾 TikTok community
Like and share our videos their whenever you can
https://www.tiktok.com/@kennel.ai?_t=8h0SUOsjUHI
#DogData #$DOGS #Web3#DogBreeder#DogNFT
Let’s bring the Dogs Data to TikTok
Join the 🐾 TikTok community
Like and share our videos their whenever you can
https://www.tiktok.com/@kennel.ai?_t=8h0SUOsjUHI
#DogData #$DOGS #Web3#DogBreeder#DogNFT
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The Kennel.Ai ecosystem has a stabil Token
https://kennel.ai/tokenomics
…use of KC stabil Token is for making either donations to street dog feeding campaign
https://kennel.ai/to-earn
or
for buying products ( on chain ) from the Webshop using crypto
https://kennel.ai/shop
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
Happy December 01 🐶🦴
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The Pet dog Industry problem is that the data collected is held on hundreds of independent servers Worldwide
25 million new pet dogs are registered with the worlds fragmented kennel clubs each year
This is a multi billion dollar industry, the average price for a pet dog now in 2023 Europe and USA is $1000-1500$
In the Future every Pet dog will be physical digital asset , data on chain
Kennel.Ai creates a unique editable NFT for each new pet dog registered
You can join the Kennel.Ai ecosystems and help tobtest the platform by registering a dog, start to earn tokens for the data provided by you and supplemental tokens for the data provided by owners of any offspring produced by your dog
https://kennel.ai/login
Kennel.Ai aims to provide one place on chain for all the worlds kennel clubs members, breeders and pet dog owners to record and own their dog life data…
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
The kennel.ai core team and team of DogShow influencers can be contacted easily through Telegram, Twitter, YouTube etc or directly by email at [email protected]
Feel free to offer marketing and promotional services
Admin @NEO55555
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
One of the core features of the Kennel.ai ecosystem is charitable donations to community that give their waste table food to street dogs
https://kennel.ai/to-earn
Millions of dog lovers worldwide care about the plight of abandoned street dogs
…that’s why Team have created the offer of being the middle man for European and American dog lovers that like to donate money to sponsor the feeding of street dogs in places like India , Romania and other countries where the street dogs need help…
at least join the platform today to show your support for this campaign 🐾
https://kennel.ai/login
Have a great day ….
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai
In our busy lives reminders are essential
How about reminders for when your pet dogs vaccinations are due for boost
Kennel.ai records dog life data on chain such as vaccination type and expiry date
Platform reminds pet dog owners when either a vaccination or booster is needed via mobile and by a notification when user is logged in to platform with Google or Web3 metamask
https://kennel.ai/login
Kennel.Ai aims to provide one place on chain for all the worlds kennel clubs members, breeders and pet dog owners to record and own their dog life data…
#dogs #$DOGS #petdog#dogbreeder#kennelclub#blockchain#Ai