Что делать если нужно поставить какую-то 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
🔴 Urgent: Gaza power blackout due to Israel's blockade prompts international condemnation. Hospitals risk becoming morgues. ICRC calls situation "abhorrent". Clean water access and healthcare at risk. HRW labels blockade a war crime, accuses Israel of collective punishment. Israel refuses aid until abducted Israelis are released. Humanitarian crisis unfolding. World urged to take action. #GazaUnderAttack#EndTheBlockade
https://www.aljazeera.com/news/2023/10/12/gaza-hospitals-risk-turning-into-morgues-rights-groups-call-for-action
Subscribe to @BadVolfNews
Retired US Army Colonel & former US diplomat Ann Wright introduces our upcoming Freedom Flotilla emergency mission to #breakthesiege and #endtheblockade of Gaza.
Ann will be a participant on the civilian flotilla sailing soon to Gaza.
LIVESTREAM FROM THE SEAS WITH THE FREEDOM FLOTILLA AND RASHIDA TLAIB.
July 23 on Instagram and Telegram
10:00 AM (New York | EDT GMT-4)
5:00 PM (Palestine | EEST GMT+3)
Join us for a powerful conversation between Congresswoman Rashida Tlaib and the U.S. citizens aboard ‘Handala’ as they sail to break Israel’s illegal siege on Gaza. Tune in to hear them discuss the moral responsibility of ordinary people when governments fail, the urgent need to change U.S. policy that enables Israel and their genocide of Palestinians, why they are sailing, what they are demanding, and how we can all stand with Gaza.
#alleyesondeck#handala#forthechildrenofgaza#breakthesiege#endtheblockade
Takis, from Greece, sailed with the Free Gaza Movement in 2008 - one of the first missions by sea that reached Gaza. Now, 17 years later, he is back, ready to help break Israel's illegal siege. #AllEyesOnDeck#DemandSafePassage#BreakIsraelsSiege#EndTheBlockade#FreeGaza🔽
Freedom Flotilla Official Update: It's time for our governments to do their jobs and sanction Israel. Its illegal attack on 'Madleen' while sailing in international waters is a small extension of their war crimes in Gaza. Governments, institutions, media, and corporations must stop protecting Israel, now. They must stop prioritising profit over human lives, now. Protect our volunteers while protecting Palestinians in Gaza and wider Palestine.
#BreakIsraelsSiege#EndTheBlockade#Madleen#FreedomFlotilla#Volunteers#IOF#StandWithGaza#StandWithPalestine
Our 'Madleen' was on a mission of urgency after a year of set backs, carrying baby formula, food, medicine, and basic humanity. Then came unidentified vessels, speedboats, quadcopters, and finally, Israeli soldiers. Francesca Albanese recounts what happened in real-time as she spoke to the crew live. She reminds us that 'Madleen' was a UK-flagged boat seized in international waters. Israel's interception is an act of piracy. Abduction is illegal, as is their siege, genocide, occupation and countless other war crimes across Palestine. So what makes a small, aid boat so scary for the Israeli occupation? According to Francesca Albanese: it is our humanity. It is everyone's defiance. It is our collective power to break the siege.
#BreakIsraelsSiege#EndTheBlockade#StandWithGaza#FrancescaAlbanese#Madleen
Bob Suberi, a U.S. and Israeli citizen and veteran, calls himself a “recovering Zionist.” Now in his third year attempting to help break Israel's illegal siege of Gaza on 'Handala', he’s taking direct action once again. After years working in Palestinian solidarity in the West Bank, Suberi is urging others, especially in the Jewish community, to speak out: “Let’s talk openly about a genocide. We’ve spent decades saying ‘Never again,’ and yet we’re justifying it.”
#BreakTheSiege#BreakIsraelsSiege#EndTheBlockade#Handala#FreedomFlotilla#StandWithGaza#StandWithPalestine
The Freedom Flotilla Coalition invites you to join us from May 30th to June 1st in Catania, Sicily, Italy, as we stand together in solidarity to launch our new mission, the ‘Madleen’.
The summit will be happening in Porto di San Giovanni li Cuti, where we will stand in solidarity with the Palestinian people in a series of panels, cultural programs, and community gatherings.
The ‘Madleen‘ will sail to break Israel's illegal siege as we bring humanitarian aid, hope, and solidarity to Gaza. The world stands united against the deliberate starvation, genocide, Apartheid, colonial occupation, and the ethnic cleansing of the Palestinian people. Join us!
Let's sail in spirit and solidarity. Free Palestine!
#FreedomFlotilla#BreakIsraelsSiege#EndTheBlockade#StandWithGaza#AllEyesOnDeck#Madleen#Conscience
Meet just some of the panelists, volunteers and supporters that will join us as we launch the ‘Madleen’ that will sail in a matter of days to break Israel's illegal siege of Gaza.
We urge media, press and supporters to join us in Catania, Sicily - your coverage and solidarity is critical in helping ensure our safety. March with us. Make noise with us. Show the world that Europe will not be silent. Share our content. Make it impossible for every politician, for the European Union and media to ignore what is happening in Gaza. Make it impossible for them to ignore the voice of the people, to ignore this mission, and to ignore this moment.
#BreakTheSiege#BreakIsraelsSiege#AllEyesOnDeck#EndTheBlockade#StandWithGaza#AllEyesOnDeck#Madleen#Conscience
Thousands of people are rising across continents - on foot, in boats, in streets and squares - to say no more.
No more siege. No more starvation. No more occupation. No more genocide. From the river to the sea, Palestine will be free. Follow and support March to Gaza today.
#BreakTheSiege#MarchToGaza#EndTheBlockade#GlobalMarchToGaza#StandWithPalestine
‘Handala’ is due to depart, just weeks after ‘Madleen’ set sail to Gaza. In a time of unprecedented levels of global repression of Palestinian solidarity, with individuals having livelihoods and careers threatened for supporting Palestine, we are reminded that repressive tactics only work if people are bullied into silence.
The ‘Handala’ mission is only one part of a global wave of solidarity. Investigative group Forensic Architecture are making an online tracker to monitor the vessel’s passage publicly available online, as with the ‘Madleen’ mission. Every act of documentation and witnessing is part of holding Israel - and complicit governments- accountable.
#FreedomFlotilla#Gaza#BreakTheSiege#AllEyesOnGaza#AllEyesOnDeck#DirectAction#EndTheBlockade#BreakIsraelsSiege
Lubna Tuma from Adalah Legal Centre provided us with a briefing on the status of the Flotilla members who were abducted from international waters by Israeli forces on 9th June 2025. Recorded just after leaving a legal counsel meeting held with the Flotilla volunteers in Givon prison, she comments on the numerous violations of human rights they were subjected to during the court hearing and in Israeli custody. Since recording Rima Hassan is no longer in solitary confinement. Please donate to Adalah Legal Centre today. QR code included and information provided at the end of the video.
#FreedomFlotilla#Gaza#BreakTheSiege#AllEyesOnGaza#AllEyesOnDeck#DirectAction#EndTheBlockade#BreakIsraelsSiege