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

Jedi has wrong sys.path when target environment has non-standard library location #1617

Closed
mrclary opened this issue Jun 19, 2020 · 4 comments

Comments

@mrclary
Copy link

mrclary commented Jun 19, 2020

@davidhalter,
Okay, when I submitted #1540, the problem arose when the host environment was a pyenv environment and the target environment was a conda environment. The solution was that the target environment should not inherit system environment variables from the host environment, i.e. the CompiledSubprocess should spawn a clean environment. Well, this works as it should when the target environment python libraries are in a standard relative location, i.e. ../lib relative to the the executable. Unfortunately, this does not work for target environments where the python libraries are not in a standard location, such as for python embedded in MacOS applications (see Spyder Mac App)

Python provides a mechanism for handling this, namely by setting the PYTHONHOME environment variable to the base directory of the libraries. This, along with other potential PYTHON... environment variables, were causing the problem outlined in #1540. Essentially, the wrong python environment variables were being inherited by the subprocess and mucking things up. In the absence of PYTHONHOME, it will find the libraries in the standard location.

So, I still think that starting a python subprocess with a clean environment is the correct paradigm, I now think that the solution provided for #1540 in #1546 is incomplete and should include a mechanism for passing explicit environment variables to the subprocess. Popen already does this, of course, with the env keyword arg. I propose modifying CompiledSubprocess to accept an env keyword argument that will be passed to the subprocess. The default should be an empty dictionary, but the user has the option to pass in envrionment variables explicitly, if needed.

What are your thougthts?

@davidhalter
Copy link
Owner

I guess this is a good proposal. Since this is not very important to me, are you willing to do this in a PR?

I would probably not name it env, but environment_variables instead. But that's really just a minor detail.

@mrclary
Copy link
Author

mrclary commented Jun 19, 2020

I'll be happy to submit the PR.
I suggested env only because that is the keyword used by Popen.
I'm not a fan of long names; how about env_vars?

@davidhalter
Copy link
Owner

That's fine.

@davidhalter
Copy link
Owner

Fixed by #1619

mrclary pushed a commit to mrclary/python-language-server that referenced this issue Jun 21, 2020
mrclary pushed a commit to mrclary/python-language-server that referenced this issue Jun 25, 2020
@mrclary mrclary mentioned this issue Jul 10, 2020
mrclary pushed a commit to mrclary/python-language-server that referenced this issue Jul 19, 2020
mrclary pushed a commit to mrclary/python-language-server that referenced this issue Aug 21, 2020
mrclary pushed a commit to mrclary/python-language-server that referenced this issue Sep 15, 2020
mrclary pushed a commit to mrclary/python-language-server that referenced this issue Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants