Что делать если нужно поставить какую-то 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
🗓 On April 23-24, the 13th ASEAN Regional Forum Open Ended Study Group on Confidence Building Measures to Reduce the Risk of Confict Stemming from the Use ofICTs (13th #ARF OESG) and the 6th ASEAN Regional Forum Inter-Sessional Meeting (#ARF ISM) on ICT Security co-chaired by Russia 🇷🇺 and Indonesia 🇮🇩 was held in Moscow in a hybrid format.
🔹️Delegations of Indonesia 🇮🇩, Singapore 🇸🇬, Thailand 🇹🇭, Cambodia 🇰🇭, the Philippines 🇵🇭, India 🇮🇳 and Bangladesh 🇧🇩 took part in the meeting in person. Chair of the United Nations Open-Ended Working Group on security of and in the use of ICTs 2021-2025, Permanent Representative of the Republic of Singapore to the UN H.E. Mr. Burhanudeen Gafoor🇸🇬 addressed the gathering with his welcoming speech.
🔹️More than 80 participants discussed future plans and cooperation within the framework of the ARF ISM on ICT Security and considered new initiatives proposed by ARF members. The meeting also exchanged views on cooperation on ICT Security-related issues within the framework of the UN and other international platforms.
🤝 On the sidelines of the events a number of bilateral meetings took place.
⚡️Russia's Foreign Minister Sergey Lavrov takes part in the 32th Ministerial Session of the ASEAN Regional Forum (#ARF) on security.
📍 Kuala Lumpur, July 11
🗓 On April 23-24, the 13th ASEAN Regional Forum Open Ended Study Group on Confidence Building Measures to Reduce the Risk of Confict Stemming from the Use ofICTs (13th #ARF OESG) and the 6th ASEAN Regional Forum Inter-Sessional Meeting (#ARF ISM) on ICT Security co-chaired by Russia 🇷🇺 and Indonesia 🇮🇩 was held in Moscow in a hybrid format.
🔹️Delegations of Indonesia 🇮🇩, Singapore 🇸🇬, Thailand 🇹🇭, Cambodia 🇰🇭, the Philippines 🇵🇭, India 🇮🇳 and Bangladesh 🇧🇩 took part in the meeting in person. Chair of the United Nations Open-Ended Working Group on security of and in the use of ICTs 2021-2025, Permanent Representative of the Republic of Singapore to the UN H.E. Mr. Burhanudeen Gafoor🇸🇬 addressed the gathering with his welcoming speech.
🔹️More than 80 participants discussed future plans and cooperation within the framework of the ARF ISM on ICT Security and considered new initiatives proposed by ARF members. The meeting also exchanged views on cooperation on ICT Security-related issues within the framework of the UN and other international platforms.
🤝 On the sidelines of the events a number of bilateral meetings took place.
🗓 On 28 April 2023 the 5th ASEAN Regional Forum Inter-Sessional Meeting (#ARF ISM) on ICT Security co-chaired by Russia 🇷🇺, Indonesia 🇮🇩 and the Republic of Korea 🇰🇷 was held in Moscow in a hybrid format.
🔹️More than 60 participants discussed cooperation on ICT Security-related issues within the framework of the ARF, UN and other international platforms.
🔹️This is the first ARF ISM on ICT Security held in hybrid format since the beginning of the COVID-19 pandemic. On its sidelines a number of bilateral meetings took place.
🗓 On 27 April 2023 the 11th ASEAN Regional Forum Open Ended Study Group on Confidence Building Measures to Reduce the Risk of Confict Stemming from the Use of ICTs (11th #ARF OESG) co-chaired by Russia 🇷🇺, Indonesia 🇮🇩 and the Republic of Korea 🇰🇷 was held in Moscow in a hybrid format to prepare for tomorrow's ARF Inter-Sessional Meeting (ISM) on ICT Security.
Delegates discussed future plans and cooperation within the framework of the ARF ISM on ICT Security and considered new initiatives proposed by ARF participants.
🗓On June 14, Deputy Minister of Foreign Affairs of the Russian Federation Andrey Rudenko 🇷🇺 participated in the ASEAN Regional Forum Senior Officials' Meeting (#ARF SOM) held online under Indonesian Chairmanship 🇮🇩.
🔹Senior officials discussed the progress achieved so far and issues related to preparation for the upcoming ARF Foreign Ministers' Meeting in July in Jakarta, Indonesia 🇮🇩.
🇷🇺 As part of the exchange of views on topical issues in the Asia-Pacific, Russian delegation voiced its approach towards the military-political risks associated with building up a network of minilateral blocs in the region and bringing NATO potential to the East Asia.
☝️ Russia reiterated its position on the maintaining and strengthening the central role of #ASEAN in regional affairs based on ASEAN-led platforms of multilateral cooperation.
🤝 Russia’s Foreign Minister Sergey Lavrov takes part in the 31th session of the ASEAN Regional Forum (#ARF) on security.
📍Vientiane, July 27, 2024
#RussiaASEAN
🗓 On June 10-11, Deputy Minister of Foreign Affairs of the Russian Federation Andrey Rudenko🇷🇺 participated in the East Asia Summit Senior Officials' Meeting (#EAS SOM) and ASEAN Regional Forum Senior Officials' Meeting (#ARF SOM) in Penang, Malaysia 🇲🇾.
🔹️Senior officials discussed issues related to preparation for the EAS Summit and EAS and ARF Foreign Ministers' Meetings later this year.
🇷🇺 The Russian Side emphasized the importance of continuing joint efforts in key areas of cooperation within the ARF and the EAS, including implementation of the leaders' decisions on launching Regional Mechanism of Emerging Infectious Diseases Prevention and Control and establishing interaction among the EAS Participating States on tourism. Russia introduced new initiatives as well – proposal to add issues of socio-cultural connectivity to the EAS agenda and increase of capacity building in the field of countering the use of ICT for criminal purposes within the framework of ARF.
🔹️ As part of the exchange of views on topical issues in the Asia-Pacific, Russian delegation voiced its approach towards the military-political risks associated with building up a network of minilateral blocs of high conflict potential in the region and bringing NATO potential to the East Asia.
☝️ Russia reiterated its position on the maintaining and strengthening the central role of ASEAN in regional affairs based on ASEAN-led platforms of multilateral cooperation such as EAS, ARF and ADMM-Plus as well as developing the platforms towards building an architecture of equal and indivisible security in the Asia-Pacific region.
#EAS#ARF
🗓 On June 7-8, Russia's Alternate SOM Leader, Director-General of the Department of Asian and Pacific Cooperation of the Russian MFA Mr. Alexey Ovchinnikov🇷🇺 participated in the East Asia Summit Senior Officials' Meeting (#EAS SOM) and ASEAN Regional Forum Senior Officials' Meeting (#ARF SOM) in Vientiane, Lao PDR 🇱🇦.
🔹️Senior officials discussed issues related to preparation for the EAS Summit and EAS and ARF Foreign Ministers' Meetings later this year.
🇷🇺 The Russian Side emphasized the importance of continuing joint efforts in key areas of cooperation within the ARF and the EAS including implementation of the leaders' decisions on launching Regional Mechanism of Emerging Infectious Diseases Prevention and Control as well as establishing interaction among the EAS Participating States on tourism.
🔹️As part of the exchange of views on topical issues in the Asia-Pacific, Russian delegation voiced its approach towards the military-political risks associated with building up a network of minilateral blocs of high conflict potential in the region and bringing NATO potential to the East Asia.
☝️ Russia reiterated its position on the maintaining and strengthening the central role of ASEAN in regional affairs based on ASEAN-led platforms of multilateral cooperation such as EAS, ARF and ADMM-Plus.
#EAS#ARF
🗓 On June 7-8, Russia's Alternate SOM Leader, Director-General of the Department of Asian and Pacific Cooperation of the Russian MFA Mr. Alexey Ovchinnikov🇷🇺 participated in the East Asia Summit Senior Officials' Meeting (#EAS SOM) and ASEAN Regional Forum Senior Officials' Meeting (#ARF SOM) in Vientiane, Lao PDR 🇱🇦.
🔹️Senior officials discussed issues related to preparation for the EAS Summit and EAS and ARF Foreign Ministers' Meetings later this year.
🇷🇺 The Russian Side emphasized the importance of continuing joint efforts in key areas of cooperation within the ARF and the EAS including implementation of the leaders' decisions on launching Regional Mechanism of Emerging Infectious Diseases Prevention and Control as well as establishing interaction among the EAS Participating States on tourism.
🔹️As part of the exchange of views on topical issues in the Asia-Pacific, Russian delegation voiced its approach towards the military-political risks associated with building up a network of minilateral blocs of high conflict potential in the region and bringing NATO potential to the East Asia.
☝️ Russia reiterated its position on the maintaining and strengthening the central role of ASEAN in regional affairs based on ASEAN-led platforms of multilateral cooperation such as EAS, ARF and ADMM-Plus.
#EAS#ARF
🎙 Russia's Foreign Minister Sergey Lavrov’s answers to media questions following his visit to Malaysia
📍Kuala Lumpur, July 28, 2024
❓Question: The US has been obsessively trying to create another training ground out of countries in the southeast. Is it relevant to say that cooperation between Russia and Asia can help the region maintain its sovereignty?
💬Sergey Lavrov: Of course. I think we had a chance to see it for ourselves yesterday and the day before in Laos during the East Asia Summit (#EAS) and the ASEAN Regional Forum (#ARF).
Russia is seen as a balancing and stabilising factor in the context of countering the extremely sharp-elbowed actions by the countries outside the region, led by the US, who push their military infrastructure, including strategic arms. <...>
Our balanced and clear stance always comes from the need to create platforms for negotiations and to agree on the basis of a balance of interests. This stance receives respect. Certainly, in contrast to the invasive and aggressive course of the US and NATO for military development of the region, our stance is closer to our #ASEAN friends.
❓Question: Last night saw another escalation in the Middle East, namely a missile attack on a football ground in the Israeli-occupied Golan Heights in which mostly children and teenagers were killed and injured. Israel has accused Lebanon, while Lebanon has put the blame on Israel. What is the likelihood of an all-out war between Israel and Lebanon? What could be done to prevent further bloodshed?
💬Sergey Lavrov: So far, we do not see any possibility of stopping the bloodshed. In response to numerous calls for a ceasefire, Israeli Prime Minister Benjamin Netanyahu has stated that Israel will not stop until it destroys Hamas completely. I believe, and many of my colleagues share this view, that the destruction of that organisation, which has significant capabilities and enjoys broad support, including in the Muslim world, is an unrealistic task.
Russia condemns all terrorist attacks committed by any group. We condemned Hamas’s terrorist attack on Israeli civilians on October 7, 2023. But Israel’s retaliatory actions have been unacceptable. They are a flagrant violation of international humanitarian law and amount to collective punishment of people, which international conventions prohibit. <...>
I am sure that the main condition for a lasting solution to the Middle East crisis is the fulfilment of the UN Security Council resolution on the establishment of a Palestinian state as soon as possible. This cannot be achieved without restoring Palestinian unity so that the Palestinians themselves can determine the format of negotiations regarding their life in a sovereign state. This goal has not yet been achieved. Efforts must continue towards this end.
Read in full
🎙 Russia's Foreign Minister Sergey Lavrov’s answers to media questions following his visit to Malaysia
📍Kuala Lumpur, July 28, 2024
❓Question: The US has been obsessively trying to create another training ground out of countries in the southeast. Is it relevant to say that cooperation between Russia and Asia can help the region maintain its sovereignty?
💬Sergey Lavrov: Of course. I think we had a chance to see it for ourselves yesterday and the day before in Laos during the East Asia Summit (#EAS) and the ASEAN Regional Forum (#ARF).
Russia is seen as a balancing and stabilising factor in the context of countering the extremely sharp-elbowed actions by the countries outside the region, led by the US, who push their military infrastructure, including strategic arms. <...>
Our balanced and clear stance always comes from the need to create platforms for negotiations and to agree on the basis of a balance of interests. This stance receives respect. Certainly, in contrast to the invasive and aggressive course of the US and NATO for military development of the region, our stance is closer to our #ASEAN friends.
❓Question: Last night saw another escalation in the Middle East, namely a missile attack on a football ground in the Israeli-occupied Golan Heights in which mostly children and teenagers were killed and injured. Israel has accused Lebanon, while Lebanon has put the blame on Israel. What is the likelihood of an all-out war between Israel and Lebanon? What could be done to prevent further bloodshed?
💬Sergey Lavrov: So far, we do not see any possibility of stopping the bloodshed. In response to numerous calls for a ceasefire, Israeli Prime Minister Benjamin Netanyahu has stated that Israel will not stop until it destroys Hamas completely. I believe, and many of my colleagues share this view, that the destruction of that organisation, which has significant capabilities and enjoys broad support, including in the Muslim world, is an unrealistic task.
Russia condemns all terrorist attacks committed by any group. We condemned Hamas’s terrorist attack on Israeli civilians on October 7, 2023. But Israel’s retaliatory actions have been unacceptable. They are a flagrant violation of international humanitarian law and amount to collective punishment of people, which international conventions prohibit. <...>
I am sure that the main condition for a lasting solution to the Middle East crisis is the fulfilment of the UN Security Council resolution on the establishment of a Palestinian state as soon as possible. This cannot be achieved without restoring Palestinian unity so that the Palestinians themselves can determine the format of negotiations regarding their life in a sovereign state. This goal has not yet been achieved. Efforts must continue towards this end.
Read in full