Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] sys.path is not accessible when subprocess is called in pynml.execute_command_in_dir_with_realtime_output #440

Open
adampdp opened this issue Jan 29, 2025 · 4 comments
Assignees
Labels
T: bug Type: bug

Comments

@adampdp
Copy link

adampdp commented Jan 29, 2025

Describe the bug

in pynml.execute_command_in_dir_with_realtime_output(),

sys.path is not accessible when subprocess is called. env['PYTHONPATH'] in subprocess overrides sys.path.

sys.path should be added to the env['PYTHONPATH'] before passing to subprocess for correct module import. See the link below:

python/cpython#105889

@sanjayankur31 sanjayankur31 changed the title [Bug] [Bug] sys.path is not accessible when subprocess is called in pynml.execute_command_in_dir_with_realtime_output Jan 31, 2025
@sanjayankur31 sanjayankur31 self-assigned this Jan 31, 2025
@sanjayankur31 sanjayankur31 added the T: bug Type: bug label Jan 31, 2025
@sanjayankur31 sanjayankur31 moved this from 🆕 New to 🔖 Ready in NeuroML backlog Jan 31, 2025
@sanjayankur31
Copy link
Member

Thanks for that. We should also check all the other functions that call subprocess to see if this issue persists there too. I'll take a look ASAP.

@sanjayankur31
Copy link
Member

@adampdp : would you have a code snippet that I can use to reproduce this please? I tried this snippet, and it does find the neuroml module, so it does seem to look at the different folders in sys.path, otherwise it wouldn't find the neuroml module:

import sys
import os
from pyneuroml.runners import execute_command_in_dir_with_realtime_output

env = os.environ

print(f'PATH is: {env["PATH"]}')
print()
print(f"sys.path is: {sys.path}")
print()
command = "python -c 'import neuroml; print(neuroml.__version__); print(neuroml.__file__); '"
execute_command_in_dir_with_realtime_output(command, directory=".")

@adampdp
Copy link
Author

adampdp commented Jan 31, 2025

@sanjayankur31

Hi, It only happens when env is set, if env is None as it would be in this code snippet subprocess uses the sys.path for env I believe. It means if env is set to some path and passed you also need to manually add sys.path to it if you want to import other modules not on the path passed in env.

@adampdp
Copy link
Author

adampdp commented Jan 31, 2025

@sanjayankur31

import sys
import os
from pyneuroml.runners import execute_command_in_dir_with_realtime_output

env = os.environ

print(f'PATH is: {env["PATH"]}')
print()
print(f"sys.path is: {sys.path}")
print()
sim_dir = './'
env = { "DISPLAY": os.environ.get('DISPLAY') if os.environ.get('DISPLAY') is not None else '',
            "XAUTHORITY": os.environ.get('XAUTHORITY') if os.environ.get('XAUTHORITY') is not None else '',
            "PYTHONPATH": ".:%s:%s" % (os.environ.get('PYTHONPATH', '.'), os.path.abspath(sim_dir)),
            "NEURON_MODULE_OPTIONS": "-nogui"}
command = "python -c 'import neuroml; print(neuroml.__version__); print(neuroml.__file__); '"
execute_command_in_dir_with_realtime_output(command, directory=".", env=env)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Type: bug
Projects
Status: 🔖 Ready
Development

No branches or pull requests

2 participants