Что делать если нужно поставить какую-то 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
🐈⬛Мы возвращаемся к вам с итогами третьей недели рубрики Q&A
🔢 Появились ли новые тенденции в исследованиях с появлением ИИ?
🔢 Может ли искусственный интеллект самостоятельно провести исследование?
🔢 Какие существуют этические нормы по использованию ИИ?
🐈⬛ На эти и другие ваши вопросы по теме «Влияние искусственного интеллекта на научную сферу журналистики и медиаисследований» ответила заведующая кафедрой цифровых медиакоммуникаций Камилла Ренатовна Нигматуллина
🐈⬛ Завтра мы вернемся с анонсом следующего гостя, а пока предлагаем вам ознакомиться с ответами эксперта
#QnA
❗️❗️❗️Dear subscribers,❗️❗️❗️ please join us for a livestream on Friday, 19 July, at 8pm GMT!
Our friend Alex at UkraineWarTruth
had his YouTube channel banned after he published the video he made in Mariupol
The banned channel was instrumental in the great work Alex has been doing since 2014, bringing the truth about the Donbass to the people in the West. It had hundreds of thousands of views and thousands of subscribers, and it was taken down without a warning after posting three new videos, which were first-hand eye-witness accounts and which didn't break a single YouTube rule.
Please join us in supporting Alex's work by watching his latest video and subscribing to his Telegram channel: https://t.me/Ukraine_War_Truth
❗️We'd also like to invite you to our upcoming livestream on Friday, 19 July, at 8pm GMT, where Alex will join #TheBelgorodBrit to speak about Mariupol, Belgorod, Russia, Ukraine... and the freedom of speech, of course!
Please post any questions or comments in this thread.
#QnA
#stream
📱InfoDefenseENGLISH
📱InfoDefense
❗️❗️❗️Dear subscribers,❗️❗️❗️ please join us for a livestream on Friday, 19 July, at 8pm GMT!
Our friend Alex at UkraineWarTruth
had his YouTube channel banned after he published the video he made in Mariupol
The banned channel was instrumental in the great work Alex has been doing since 2014, bringing the truth about the Donbass to the people in the West. It had hundreds of thousands of views and thousands of subscribers, and it was taken down without a warning after posting three new videos, which were first-hand eye-witness accounts and which didn't break a single YouTube rule.
Please join us in supporting Alex's work by watching his latest video and subscribing to his Telegram channel: https://t.me/Ukraine_War_Truth
❗️We'd also like to invite you to our upcoming livestream on Friday, 19 July, at 8pm GMT, where Alex will join #TheBelgorodBrit to speak about Mariupol, Belgorod, Russia, Ukraine... and the freedom of speech, of course!
Please post any questions or comments in this thread.
#QnA
#stream
📱InfoDefenseENGLISH
📱InfoDefense
Qatar News Agency
Kazakh Vice Minister of Culture, Sports: Close Relations Between #Kazakhstan and #Qatar, Large Cooperation Projects Await Both Sides.
Chairman of the Management Board of JSC National Company “Kazakh Tourism” to #QNA: After HH the Amir's visit, we hope to establish great cooperation between #Kazakhstan and #Qatar, especially in the field of tourism.
Daily Questions-Answers, Facts, Idioms, Riddles and Quotes
#QnA
1. The pollutants which move downward with percolating groundwater are called
Ans . Leachates
2. Hasdo Valley in Chhattisgarh is famous for
Ans . Coal mines
3. Special Theory of Relative was proposed in
Ans . 1905
Via @askmenow
--------------------------------
#DidYouKnow
Eiffel Tower is six inches taller in summer due to 'Thermal Expansion'
#Idiom
"A hot potato"
What it means?Check Answer
#Riddle
"Where does today come before yesterday'
What is it?Check Answer
#Quote
"Optimism is a happiness magnet. If you stay positive, good things and good people will be drawn to you."
~ Mary Lou Retton
-----------------------------
Partnership with:Be Like Bro, sarcasticLOL, News Clips, Word Coach, Quiz MCQ, Ask Me Idiom & Ask Me Riddle
Daily Questions-Answers, Facts, Idioms, Riddles and Quotes
#QnA
1. Celsius and Fahrenheit show the same temperature at
Ans . 40
2. Exchange particle in Quark-Quark Interaction
Ans . Gluon
3. The working of a rockets based on the principle of:
Ans . Conservation of momentum
Via @askmenow
--------------------------------
#DidYouKnow
There are ice caves in Iceland that have hot springs.
#Idiom
"Letting the cat out of the bag"
What it means?Check Answer
#Riddle
"What has words, but never speaks"
What is it?Check Answer
#Quote
"Two roads diverged in a wood and I took the one less traveled by, and that made all the difference."
~ Robert Frost
-----------------------------
Partnership with:Be Like Bro, sarcasticLOL, News Clips, Word Coach, Quiz MCQ, Ask Me Idiom & Ask Me Riddle
Daily Questions-Answers, Facts, Idioms, Riddles and Quotes
#QnA
1. In Computer, what is the full form of UPS?
Ans . UPS = Uninterruptable Power Supply
2. Which city is built on more than 100 islands?
Ans . Venice
3. Name of vegetable which is also known as a flower?
Ans . Broccoli
4. Highest electrical conductivity found in which element?
Ans . Silver
5. Thermometer made first by?
Ans . Gauss
Via @askmenow
--------------------------------
#DidYouKnow
Lions have been observed to rest for a major part of the day, usually around 20 hours.
#Idiom
"A blessing in disguise"
What it means?Check Answer
#Riddle
"What can you hold in your left hand but not in your right"
What is it?Check Answer
#Quote
"Circumstances are beyond the control of man, but his conduct is in his own power."~Benjamin Disraeli
-----------------------------
Partnership with:Be Like Bro, sarcasticLOL, News Clips, Word Coach, Ask Me Idiom & Ask Me Riddle
Daily Questions-Answers, Facts, Idioms, Riddles and Quotes
#QnA
1. White Revolution’ is related to what?
Ans . Milk Production
2. A very successful invention ‘Liquid Oxygen’ discovered by whom?
Ans . Dewar
3. What is the radiant energy of the sun is transmitted?
Ans . Short waves
4. What is the chemical formula of ‘Sodium Hydroxide’?
Ans . NAOH
5. The Folded Earth book was written by?
Ans . Anuradha Roy
6. Barometer was invented by?
Ans . F. Banting
7. Which rays is very helpful in Long distance photography?
Ans . Infra-Red rays
Via @askmenow
____________________
____________________
#DidYouKnow
Grasshoppers have ears in their bellies
#Idiom
"A bird in the hand is worth two in the bush"
What it means?Check Answer
#Riddle
I’m light as a feather, yet the strongest person can’t hold me for five minutes.
What am I?Check Answer
#Quote
"If you spend your whole life waiting for the storm, you'll never enjoy the sunshine." ~ Morris West