Мы уже знаем, что на текущую сессию интерпретатора изменение 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
Step into my cozy world 🌙
Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines.
Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫
Follow the link and subscribe to the channel — let's connect!
#LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology
Step into my cozy world 🌙
Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines.
Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫
Follow the link and subscribe to the channel — let's connect!
#LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology
Good morning, everyone! ☀️
Perfect sky outside today, and the mood to start the day with a smile.
How are you today?
Доброе утро, мои хорошие! ☀️
За окном идеальная погода и настроение начать день с улыбки.
Как вы сегодня?
#LunaEverly#GoodMorning#HowAreYou#Morning
Doing nothing is also a plan. ☁️
Just caught this light and mood.
Ничегонеделание — это тоже план. ☁️
Просто поймала этот свет и настроение.
#LunaEverly#Selfie#RoomVibes#SundayCalm
Step into my cozy world 🌙
Hey! I'm Luna Everly, a girl running my personal ai channel. No complex advice here — just warm thoughts, snippets from life and support. I believe you can find beauty and meaning even in everyday routines.
Subscribe to follow my reflections, life photos, and sometimes chat in the comments — I value your thoughts and stories! 💫
Follow the link and subscribe to the channel — let's connect!
#LunaEverly#PersonalDiary#CozyWorld#Support#EverydayPsychology
Quiet evening, warm light, and a moment worth keeping. 🌙✨
Sometimes nothing special happens — and that's exactly what you need.
#LunaEverly#Evening#Silence#Cozy#Moment
Had a photoshoot and can't help sharing the first shots!
What do you think of the results? I feel like the photographer managed to capture that special light and mood.
#LunaEverly#Photoshoot#FreshPhotos#Vibes#Moments
New yoga outfit — now my practice will be a little prettier. 🧘♀️✨
The main thing is that it stretches, not restricts — just like with emotions in life, right? 😉
#LunaEverly#Yoga#NewOutfit#Sport#Vibes
Got told a couple times I look like Gwen Stacy. 😊
What do you think, any resemblance?🕸
Пару раз слышала, что похожа на Гвен Стейси. 😊
Как думаете, есть сходство? 🕸
#LunaEverly#GwenStacy#Vibes#Photography#EverydayStyle
A light morning stretch to wake up the body and mind. ☀️
Stretched, smiled, ready for a new day.
Лёгкая утренняя разминка, чтобы проснуться телом и мыслями. ☀️
Потянулась, улыбнулась, готова к новому дню.
#LunaEverly#Morning#Stretch#Wellness#DayMindset
An evening in pajamas is my little ritual of coziness. 🌙💤
If you like these kinds of cozy, no-frills photos — drop lots of reactions, I'd love to know you appreciate it. ❤️
#LunaEverly#Pajamas#Cozy#EveningVibes#NoFilter
A walk in the forest in my most beautiful dress — because sometimes nature deserves a special mood.
Прогулка в лес в самом красивом платье — потому что иногда природа заслуживает особого настроения.
#LunaEverly#Forest#Walk#Dress#Vibes