Мы уже знаем, что на текущую сессию интерпретатора изменение PYTHONPATH никак не повлияет. Но если вы запустите дочерний процесс, то он унаследует окружение текущего процесса, а значит и изменения в любых переменных будут на него влиять.
Вот небольшой пример:
Объявляем переменную
user@host:~$ export PYTHONPATH=/path1
Запускаем интерпретатор
user@host:~$ python3
Проверим что в sys.path
>>> import sys
>>> print(sys.path)
['', '/path1', '/usr/lib/...', ...]
Добавляем что-то в переменную
>>> import os
>>> os.emviron['PYTHONPATH'] = '/path1:/path2'
>>> print(sys.path)
['', '/path1', '/usr/lib/...', ...]
Изменений нет. Но давайте запустим дочерний процесс и посмотрим там
>>> os.system('python3')
# теперь мы находимся в другом процессе
>>> import sys
>>> print(sys.path)
['', '/path1', '/path2', '/usr/lib/...', ...]
Тоже самое будет и с subprocess, так как по умолчанию текущее окружение тоже наследуется.
>>> import subprocess
>>> subprocess.call(['python3', '-c', 'import sys;print(sys.path)'])
['', '/path1', '/path2', '/usr/lib/...', ...]
______________________
Лучшей практикой является передача энвайронмента явно через аргумент env!
import subprocess
subprocess.call(cmd, env={'PYTHONPATH': '...'})
Это поможет точно понимать какое окружение будет у запускаемого процесса и при этом не изменять окружение текущего процесса.
#basic
🐹Solution for the mini-game
in Hamster Kombaton September21!
💎Receive a diamond for completing the task!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:Daily Combo for August30th!
🔸 Cointelegraph
🔸 Risk management team
🔸 Setting up business processes
Combine these cards to win 5,000,000 coins! 💰
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Alert!
📝Your Human Talent
💡 Is your most important talent.
📊Profit per hour: +1.5K
💰Cost: 35,000 coins
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Alert!
🔍 No Expensive Mistakes
If you don’t manufacture a quality product, all you’ve got at the end is a bunch of expensive mistakes.
💰 Profit per hour: +800
💸 Cost: 17,000 coins
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat :New Card Alert for August 28th!
🗣️ Speak Clearly, If You Speak at All
“The way to get started is to quit talking and begin doing.”
Profit per hour: +400
Cost: 10,000 coins
🔔🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Solution for the mini-game with a key inHamster Kombaton August 27th! 🔑
➕A new mini-game has been added!
Now, connect hexagon tiles of the same color to earn coins.
⭐️Play as many times as you want!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat :New Card Alert for August27th!
🌾 Feed a Growing Population & Enhance Food Security
In the next 30 years, we will need to produce as much food as was produced in the last 10,000 years.
Profit per hour: +4K
Cost: 60,000 coins
🔔🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Solution for the newmini-game
in Hamster Kombaton August 26th!
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap
🐹Hamster Kombat:New Card Added!
🌕MoonPay is now available!
A whole world of crypto in one simple account. Buy, sell, and swap seamlessly. Say hello to the new way to crypto!
💰Earn 20K per hour with this card.
🔔Subscribe👉Join Hamster
⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️
#crypto#hamster#key#code
#hamsterkombat#chiper#taptap