-
-
Notifications
You must be signed in to change notification settings - Fork 382
Fix losing the venv context on Linux #197
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
Conversation
Possibly fixes #42 It looks like calling the executable as a string is doing something when executed to lose the venv context, which is causing all of the module not found errors.
Can you share the error that you were getting? I rejected this exact commit from someone else because it was working for everyone besides certain Linux users. If I can get a better exception that happens to you, I can see if there is a way I can make it more cross-platform. |
It's all my comments in #42, everything works until the viewer reloads and then it can't find the modules anymore:
After installing python3-psutil so it was available globally, it errored on the next import which was 'dateutil'. I think passing the quoted string is causing execv to create the process outside of the current venv? Or maybe the python interpreter inside the venv uses its path to find the modules directory, and isn't accepting the quotes? |
This is the installed modules inside the venv:
|
Minimum reproduction(test.py) import dateutil
print('test!') Not workingimport sys
import os
system_args = [f'"{sys.executable}"'] + ['test.py']
os.execv(sys.executable, system_args)
Workingimport sys
import os
system_args = [f'{sys.executable}'] + ['test.py']
os.execv(sys.executable, system_args)
|
It is an issue with the venv executable's path. Both the executable path is wrong and the venv packages directory isn't added to sys.path. test.py import sys
print(sys.path)
print(sys.executable)
print(sys.argv) With quotes['/opt/plot-manager', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages'] Without quotes['/opt/plot-manager', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/opt/plot-manager/venv/lib/python3.8/site-packages'] |
I can confim, that this PR fixed my issue when running
For the installation of swar I followed the instructions in detail (including venv).
Inside venv:
|
Sorry for the delay in my response. I have been trying to knock out a bunch of these PRs while also answering the pile of questions I've been getting messaged from every different avenue. I ran this change without the quotes and here is the issue that I have:
Now I wonder if this issue is how Linux works in general or if it's specifically with certain Linux users. Because if it's just with certain Linux users, this is a super easy fix for me to implement with just detecting if it's Windows or Linux. |
Oh it doesn't work if you have spaces like I do right now, that's why I added quotes. Need to figure out a quick fix to this issue |
when you get a moment, can you see if the following line of code works for you. system_args = ['python'] + sys.argv I think that should work, I just need a quick sanity check. I don't know why I didn't do that before. |
No worries! I see that, it looks overwhelming tbh. Especially when the answers to a lot of this are "your Chia install is broken" or "you need to forward port 8444" or "you should learn about file permissions" 😆
Lol that totally works... it seems so obvious but I didn't think of it either. I'm sort of flabbergasted that there's not a way to do this more easily, I did a lot of googling about it before this PR. There is a difference though if I look at my minimal case: the search path doesn't include the venv packages, but when I run test.py import sys
print(f'path: {sys.path}')
print(f'executable: {sys.executable}')
print(f'argv: {sys.argv}') Beforelaunch.py import sys
import os
system_args = [f'{sys.executable}'] + ['test.py']
os.execv(sys.executable, system_args) $ venv/bin/python launch.py Afterlaunch.py import sys
import os
system_args = ['python'] + ['test.py']
os.execv(sys.executable, system_args) $ venv/bin/python launch.py |
Thank you! Very quick response. I'll get this merged out to the development branch. |
Thank you! |
Possibly fixes #42
It looks like calling the executable as a quoted string is doing something when executed to lose the venv context, which is causing all of the module not found errors.