Мы уже знаем, что на текущую сессию интерпретатора изменение 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
#java#gale#java#keyi#minecraft#minecraft_performance#minecraft_server_software#mirai#paper
Leaf is a high-performance, customizable Minecraft server software based on Paper, designed to improve game speed and flexibility. It supports asynchronous pathfinding, mob spawning, and entity tracking, making gameplay smoother. Leaf is compatible with Spigot and Paper plugins, supports all username characters, fixes some Minecraft bugs, and uses a disk-saving file format. It integrates error tracking for easier server maintenance and keeps dependencies up-to-date. This means you get a faster, more stable Minecraft server with better plugin support and easier management, enhancing your overall gaming experience. Java 21 or higher is required to run it.
https://github.com/Winds-Studio/Leaf
🇯🇵 Elezioni #Giappone – Clamoroso exit poll di TBS: Il Partito Liberal Democratico della premier #Takaichi potrebbe da solo ottenere per la prima volta nella storia la super maggioranza dei 2/3 per cambiare la Costituzione.
Governo: 356
#LDP (conservatori): 321
#Ishin (destra libertaria): 35
Opposizione: 109
#CRA (centro): 50
#DPFP (centrodestra): 29
#Sanseito (estrema destra): 11
#Mirai (democrazia digitale): 8
#JCP (comunisti): 3
Altri: 8
@UltimoraPolitics24
#go#coolq#cqhttp#cqhttp_mirai#go#go_cqhttp#golang#group_manager#mirai#mirai_bot#nonebot#onebot#onebot_plugin#onebot_sdk#plugin#qq#qq_bot#qqbot#qqrobot#websocket#zerobot
ZeroBot-Plugin is a comprehensive utility plugin collection for the ZeroBot chatbot framework, offering over 100 features across entertainment, management, and productivity categories. The system provides high-priority functions like chat management, sleep tracking, and group administration, alongside mid-tier features such as image generation, music streaming, and game simulations. Users benefit from flexible plugin control—enabling or disabling specific features per group—and dynamic loading capabilities that reduce program size. The platform supports multiple deployment methods, from pre-compiled releases to local compilation, making it accessible whether you prefer ready-to-use binaries or customized builds. With extensive command options, scheduled task triggers, and AI integration, ZeroBot-Plugin transforms group chat management into an automated, entertaining experience while maintaining user control over which features activate in specific communities.
https://github.com/FloatTech/ZeroBot-Plugin