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
Ensure correct sys.path contents in Windows, for sub-processes launched by Mu #726
Conversation
…x minor zoom bug.
With regard issues #612 and #581 everything worked well in all of the situations I tried. With regard importing a module for I'm not exactly sure why this is the case. Printing out
I'm sorry this probably isn't the best news for your Saturday morning. If there's anything you want me to try on my machine just let me know. EDIT: Trying the same thing with file in other locations: The installed version will import a file from the directory of the file being run in debug mode only, so it seems like something about the way files are imported in debug mode includes the current directory, but not when run normally. (Everything still works fine in the virtualenv version). |
@tim-mccurrach can you run the following script and copy the full output into a comment on this issue. Can you also attach your log file too please..?
Thank you! |
@ntoll Just from a quick perusal of the code... At least on my system, site.USER_SITE doesn't exist by default. (You can actually see this if you run python -msite). And AFAICT we're not creating it. I'm actually surprised we're not seeing some kind of filesystem error. I'll try to have more or a look later today or tomorrow |
Running the installed version of v1.0.2 I get the following output:
When running in debugger mode:
Last part of log file attached: |
Well that was an interesting exploration into the somewhat messiness ofo the site/isolation flags. I was particularly confused by the fact that the virtual environment I was working in for development turned off In case it helps anyone, I've been using this code to try out different environments: https://gist.github.com/tjguk/babef6799c87b3a5e2c240ca8add9c45 The business with the "USERPROFILE" is because I use a different user for installed as opposed to development Mu. Anyhow, the long and short seems to be that adding a simple os.makedirs(site.getusersitepackages(), exist_ok=True) is likely to set things right. I'll experiment a bit more but I'll probably just mod the PR with that. |
@tjguk @tim-mccurrach Aha... this feedback is invaluable, and I think I can see what the problem is. @tim-mccurrach the reason it's not working for you is because the So here's where I've slipped up. I've used the Ergo, the simplest solution is to replace assignments from the I'll push that change later today. Please re-test. :-) |
Just updating after a quick conversation with @ntoll elsewhere. In short: he'd misunderstood the question of whether |
…ks to Tim for the pointers.
@tjguk @tim-mccurrach OK... thanks to Tim for the heads up on the actual behaviour needed. I've just pushed a small change to fix this (and updated the tests). Please test! I'm off to play Christmas carols with the local brass band and will catch up later today... 🎺 🎵 🎄 👍 |
@tjguk @tim-mccurrach could you please confirm things work with this PR? It's one of the final blockers for a 1.0.2 release. Thanks. |
Sorry; setting time aside this evening |
Thank you! |
Ok; I can confirm that, on an installed version of Mu, I was able to import from another module within the mu_code directory. |
... and that, if I load a file from another directory (ie not mu_code), then I am able to import files from that directory as well as from the mu_code directory. |
Thanks for the heads up. Merging for 1.0.2 release. |
This PR introduces three changes.
mu.pth
file in the directory Python/Windows reports as theUSER_SITE
(a directory that's usually writeable by the user, but which Python checks for configuration files when it starts up). If this step fails, Mu logs the error and continues as it used to behave (but the user will thus encounter the import errors reported in the referenced issues). The problem was caused by the version of Python used by the Windows installer for Mu running in "isolated" mode (i.e. protected from other versions of Python that may be installed on the system).pythonXX.zip
(where XX is Major/Minor numbers of the Python version) is included in thesys.path
. This is simply an injection of the location ofpython36.zip
intosys.path
before the debugger kicks off the script-to-be-debugged.While a relatively small PR, the path related issues took a while to figure out since there were various (and ultimately unusable) potential approaches which needed to be checked before I could be sure I had a "good" solution. I believe the approach taken here meets both the "it's simple" and the "it works" heuristics. However, I'm painfully aware that I'm no Windows expert nor do I have a Windows machine available to me which would allow me to check some of the more "weird" configurations Mu is likely to encounter (especially in school based environments).
As a result, I'd love some feedback from Windows-related folks before merging. :-)
cc/@tjguk and @tim-mccurrach