Мы уже знаем, что на текущую сессию интерпретатора изменение 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
✨New Character on #PixelTap, Fight with the leading meme coin on Avalanche: COQ INU
🐓 Once upon a time, in a small village, lived COQ, a poor rooster with big dreams. He made a living by selling a few eggs, hoping for a better future.
One day, COQ met a beautiful hen named Bella. They fell in love, and with Bella's care and COQ’s commitment to his work, their hens began laying the most delicious eggs. This lucky break felt like an avalanche of opportunity.
Believing in his dream, COQ created "Golden Valley Eggs," with beautiful packaging and a touching love story. People adored their eggs, and the business boomed. Overnight, COQ went from rags to riches, surprising everyone with his success.
Now, COQ is a KING, wearing fine Italian suits and a golden crown, ruling his egg empire with pride.
His journey showed that with a bit of luck and believing in your dreams, anyone can find success.
— Fight with COQ on PixelTap👈
👩🚀➖
🎁#PixelTap#Pixelverse Combo of the Day.
PixelTap has introduced the Combo of the Day, where you can earn very large rewards
🤑
https.://t.me/pixelversexyzbot👈
➖➖➖➖➖➖➖➖➖➖➖
🏆9 new promising projects👍
👉1️⃣HOT NEAR Wallet
👉2️⃣Blum
👉3️⃣MemeFi
👉4️⃣Bull Run
👉5️⃣Cityholder
👉6️⃣TimeFarm
👉7️⃣PocketFi
👉8️⃣Cyber Finance
👉9️⃣Dogshouse_bot/🆕👈
👉1️⃣0️⃣Notcoin Platinum🆕👈
➖➖➖➖➖➖➖➖➖➖➖
🎁#PixelTap#Pixelverse Combo of the Day.
PixelTap has introduced the Combo of the Day, where you can earn very large rewards
🤑
https.://t.me/pixelversexyzbot👈
➖➖➖➖➖➖➖➖➖➖➖
🏆9 new promising projects👍
👉1️⃣HOT NEAR Wallet
👉2️⃣Blum
👉3️⃣MemeFi
👉4️⃣Bull Run
👉5️⃣Cityholder
👉6️⃣TimeFarm
👉7️⃣PocketFi
👉8️⃣Cyber Finance
👉9️⃣Dogshouse_bot/🆕👈
👉1️⃣0️⃣Notcoin Platinum🆕👈
➖➖➖➖➖➖➖➖➖➖➖
🎁#PixelTap#Pixelverse Combo of the Day.
PixelTap has introduced the Combo of the Day, where you can earn very large rewards
🤑
https.://t.me/pixelversexyzbot👈
➖➖➖➖➖➖➖➖➖➖➖
🏆9 new promising projects👍
👉1️⃣HOT NEAR Wallet
👉2️⃣Blum
👉3️⃣MemeFi
👉4️⃣Bull Run
👉5️⃣Cityholder
👉6️⃣TimeFarm
👉7️⃣PocketFi
👉8️⃣Cyber Finance
👉9️⃣Dogshouse_bot/🆕👈
👉1️⃣0️⃣Notcoin Platinum🆕👈
➖➖➖➖➖➖➖➖➖➖➖
🎁#PixelTap#Pixelverse Combo of the Day.
PixelTap has introduced the Combo of the Day, where you can earn very large rewards
🤑
https.://t.me/pixelversexyzbot👈
➖➖➖➖➖➖➖➖➖➖➖
🏆9 new promising projects👍
👉1️⃣HOT NEAR Wallet
👉2️⃣Blum
👉3️⃣MemeFi
👉4️⃣Bull Run
👉5️⃣Cityholder
👉6️⃣TimeFarm
👉7️⃣PocketFi
👉8️⃣Cyber Finance
👉9️⃣Dogshouse_bot/🆕👈
👉1️⃣0️⃣Notcoin Platinum🆕👈
➖➖➖➖➖➖➖➖➖➖➖