Мы уже знаем, что на текущую сессию интерпретатора изменение 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
#from#beautiful
A mother and a child on a wooden horse photo, in the style of gritty urban realism, new american documentary photography, mixed media installations, cheyenne art, rural life depictions, colorized, suburban ennui capturer --ar 103:128 --v 6.0
✅pitpeterssen _Midjourney v6.0
🚀Boost this Channel
@ai_artz🌿
#from#beautiful
Beautiful indian woman flying up in the sky with her aircraft chair, clouds moving in full speed, woman streching her hands on clouds, her hair also flying in speed, minimal, shot with Sony Alpha with wide angle lens, 16k, candid, aperture F1.2, full detail shot, dramatic lighting, --ar 16:9
✅ Vinaysaya _Discord
@ai_artz
#from#beautiful
Portrait and fashion photography: a combination of renaissance costumes and snowflakes, texturing, ::elegant clothes worn by the most beautiful women, a woman with a wonderful face and expressive eyes, beautiful delicate makeup, the highest quality, translucent floral fabrics, simple and aesthetic hairstyles, dynamic poses, neutral interesting dark background, award winning fashion photography, photorealistic, bright, elegant, golden ratio, elite, highly detailed, color triad, dynamic composition, ultra resolution, ultra wide shot, digital art, world made of light, soft lighting, unreal engine, depth of field 8k, full hd photo, HDR, high resolution photography, macro photography, beautiful highlights, zbrush art, photoshop, studio setting, simple, neutral, grainy, matte, fashion style :: Canon EOS 5D Mark IV EFL 100mm, f /1.4, ISO 50, 1/100 sec, Eye Sharpness, RAW, v4 - a r 2:3 - 800 sec, Chaos 49
✅ Adora _Discord
@ai_artz
#from#beautiful
An underwater urbex guerilla garden with old cars on the shoal underwater ::directional light, cinematic, alcohol ink and cinematic, saudek and sorayama ::hyperrealistic --ar 3:2 --q 2 --upbeta --s 750 --v 5.1
✅ Prima Demonessa _Discord
Join us for more @ai_artz
#from#beautiful
Gouache painting of a book-nook diorama of a cryptid conservatory, has incredible attention to detail, intricate, highly detailed, fantastic realism, fantasy, magical, led lights, --q 2 --s 750
✅ Adriann _Discord
@ai_artz
#from#beautiful
Photography of the living room of a huge hotel on Mars, futuristic Hotel on Mars furnished in japanes style, 8k, photo realistic, beautiful japanese design, welcoming Hotel, ultra realistic, ultra detaile
✅ Max05 _Discord
@ai_artz