Что делать если нужно поставить какую-то 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
✈️Another new international flight
🇦🇺 AirAsia will launch a new Bali to Adelaide (Australia) flight. The flights between Adelaide and Denpasar will commence from June 25 this year, becoming the first low-cost carrier on this route.
ℹ️ The four flights per week will be operated by an A320-200 with a capacity of 180 seats. Passenger traffic at Adelaide Airport is expected to increase to 74,000 people per year once the new route is introduced.
@BaliNews
#tourism#destinations
🇫🇷🇷🇺Thomas Rodriguez, organisateur de voyages à travers la Russie: l'Anneau d'or est une destination incroyable.
J'ai envie de recommander à tous ceux qui veulent venir en Russie de voir l'Anneau d'or. Ce sont des destinations vraiment incroyables parce que c'est juste à côté de Moscou, donc en termes ne serait-ce que d'organisation, c'est beaucoup plus facile. Et il y a des villes qu'on peut visiter en une journée, même en prenant le temps, qui montrent, comme Serguiev Possad, même Kostroma, Yaroslav, toutes ces villes-là sont incroyables, dans le sens où on voit une Russie qui est différente, plus ancienne.
#russie#voyages#destinations
📰Garuda Indonesia launches direct flight between Halim and Bali
✈️ Garuda Indonesia has begun operating daily flights between Halim Airport in Jakarta and Ngurah Rai Airport in Bali. The new route is designed to make travel between the capital and the island faster and more convenient, as well as to relieve congestion at the crowded Soekarno-Hatta Airport.
📍 Halim is located just 12 km from the city center, where most countries' consulates are located and from where passenger trains depart for destinations across the island of Java.
#goodnews#destinations#tourism@BaliNews
🇻🇳 Vietnam Airlines launches direct flights from Ho Chi Minh City to Bali from June
📅 Vietnam Airlines will launch a new direct route between Ho Chi Minh City, Vietnam and Denpasar, Bali from June 1. Flights will operate four times a week.
✈️ There will now be 14 direct flights per week between Vietnam and Indonesia. Currently, flights between Ho Chi Minh City and Bali are operated by VietJet Air. The arrival of the new operator will give travelers more choices and options.
@BaliNews
#goodnews#destinations#tourism
✈️New flights from Bali: Guangzhou, Jeddah, Perth and domestic routes
🇨🇳TransNusa airlines has become the first Indonesian carrier to launch a Bali – Guangzhou (China) flight.
🎫 Tickets for the new flight are on sale at a promotional price of $149.
🇦🇺 Meanwhile, TransNusa also launched a connecting flight between Guangzhou and Perth, Australia.
🇸🇦 And Saudi Airlines announced the arrival of a direct flight from Denpasar to Jeddah.
@BaliNews
#goodnews#destinations#tourism
✈️From Saudi Arabia to Bali by direct flight
📰Saudia Airlines has launched flights from Jeddah to Bali.
🕋Saudia, the national carrier, has officially launched flights between Bali and Jeddah, the “gateway to Mecca” for pilgrims.
ℹ️Saudia Airlines will operate flights from Jeddah to Bali three times a week with a Boeing 787-900 Dreamliner.
@BaliNews
#destinations#tourism#culture
🔤🔤🔤 flights are lanched by Indonesian airlines
✈️Garuda, Lion Air, Citilink and Batik Air have launched new flights.
・Indonesian airline Garuda Indonesia has launched new flights between Denpasar-Balikpapan (Kalimantan) and Balikpapan-Makassar (Sulawesi). This is part of the airline's wider mission to support the development of Indonesia's new capital city of Nusantara.
・Lion Air will fly the Denpasar - Medan (Sumatra) route every Tuesday, Wednesday, Thursday, Friday from December 6, 2024.
・Citilink has launched a flight from Jakarta (Halim Airport) to Wei Kanan (Lampung, Sumatra) from November 20. The flights are operated twice a week – on Wednesdays and Sundays.
・Batik Air started daily flights from Bengkulu (BKS) to Jakarta (CGK) from November 2024. In addition, the company has connected Kuala Lumpur with four Indonesian destinations – Lombok, Surabaya (East Java), Padang (Sumatra) and Pekanbaru (Riau) with direct flights.
@BaliNews
#transport#airport#destinations
🇵🇪 Indonesia opens its doors: Peru granted visa-free travel
📰 Following Brazil and Turkey, Indonesia has added Peru to its list of visa-exempt countries.
🤝 The key factor is reciprocity: Peru already allows Indonesian citizens to visit without a visa. Now, Peruvians enjoy the same privilege for traveling to Indonesia.
#tourism#visa#destinations@BaliNews
🇨🇳 The new Bali to Guangzhou flight details
A convenient connection to Perth and a chance to linger on the island.
✈️TransNusa opens a direct Bali - Guangzhou flight and becomes the first Indonesian carrier on this route! The first flight will take place as early as April 13.
We are pleased to offer this flight and hope that passengers will not just wait for a connection but stay longer in Bali,
said TransNusa.
Why it's important?
・It makes traveling between China, Bali and Australia easier.
・Travelers from Guangzhou will be able to get to the island faster and cheaper.
・ Australian residents get a convenient connection to Bali on their way to China.
Flight details:
・Promo fares from $149 one-way.
・ Convenient connections for those flying from Guangzhou to Perth and back.
・ The connection to Bali will take 1.5 to 2.5 hours, depending on flight times.
Schedule:
Guangzhou - Perth (via Bali) - Monday, Tuesday, Thursday.
Perth to Guangzhou (via Bali) - Monday, Saturday.
@BaliNews
#tourism#airport#transport#destinations
✈️ New flights to Bali
Bali is steadily becoming a more sought-after destination for travelers from all over the world every year. To meet the growing demand, airlines are launching new flights to the island.
🇹🇭AirAsia: Bali to Phuket
AirAsia is launching a direct service between Bali and the popular resort of Phuket. Flights operate three times a week, on Tuesdays, Thursdays and Saturdays. Travel time is about four hours.
🇨🇳Hong Kong Airlines: Hong Kong to Bali
Hong Kong Airlines resumed flights to Bali after the pandemic, flying on Airbus A333s. Cathay Pacific was previously the only airline flying this route.
🇦🇪Emirates: Dubai to Bali
Emirates is doubling the number of flights to Bali using the Airbus A380. The flights will operate twice daily from September 1 to October 26.
🇷🇺Aeroflot: Moscow - Bali
Starting September 17, Aeroflot launches direct flights to Bali. The flight time is 12 hours. Tickets are already on sale.
✈️ Phuket – Bali
✈️ Hong Kong – Bali
✈️ Dubai – Bali
✈️ Moscow – Bali
@BaliNews
#wheretogo#airport#destinations#transport
✈️AirAsia launches new Bali to Darwinflight
📆 Popular low-cost carrier AirAsia is set to launch a new flight between Darwin (Australia) and Denpasar from March 22, 2025.
⏰ The flights will operate every Tuesday, Thursday and Saturday: Denpasar - Darwin 11:40 - 15:55, return 16:35 - 17:55.
@BaliNews
#transport#planes#destinations