-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Session.run finds incorrect Python #256
Comments
Fellow user here. It seems weird to me that To take a step back: I'm using conda, too and I think I (so far) only saw I understand that you checked that the environment works correctly, but just to be sure, in order to exclude the possibility that something strange is happening there, and find out more, could you humour me and try out the following commands after activating the environment in question in a command line window: $ where python
$ set path
$ python -c "import sys; print(sys.executable)"
$ python -c "import py; print(py.path.local.sysfind('python'))" Depending whether the results are what you expect, it should then become clear whether the environment itself may be contributing to the issue by setting a wonky |
I think we should make clear what environment we are taking about. There is my environment that hosts the project. Let's call this env "project". In my nox file I inform nox to create two more envs, one for "python 3.6" and another for "3.7". It inform nox to use conda to manage these. NOX then creates these envs using conda. These are the environments meant to be in use when running the nox session (test function). So as for your request. Are you asking me to activate these environments that nox created? Im not on my computer now but I do believe they show up when using "conda info --envs". However they don't have any name just a path. Finally I just want to be clear. Path is not none. It is what I stated above. I checked this through a debugger. I followed the logic before how path was initiialzed and it made sense but don't remember now. I'll try to show the trace to you later. |
Here is a list of the environments nox created with conda. It is the first two listed:
I activate manually here with this command (as requested):
Output of
This does not seem to be the correct python it should find. I was hoping/expecting for However my feeling is that is isn't entirely the issue. I mentioned how This variable is actually passed as For windows this path (self.bin) is the For Linux this is different, So I think the problem is that for a windows python conda installation, two directories need to be searched. The base python installation and the |
Thanks a lot for the thorough analysis! 👍 Pretty weird that things seem to be wonky both on the conda level (PATH env var not set correctly, however apparently inconsequential for this problem) as well as the nox level, where I now see that, for Windows, I just checked on a Windows machine (Anaconda 4.7.11) that I have access to, and I can confirm that the Side note: I indeed mixed things up a bit in my previous post -- For some reason I thought that |
Yep. As for now things are working because I just manually hardcoded nox to also look at the main python installation. However not sure if that's the correct thing to do. |
I used Nox constructs an absolute path to the binary when running a command. https://sourcegraph.com/github.com/theacodes/nox@ac0992332a266f85152db8a5252b1fdf9818eb75/-/blob/nox/command.py#L87 This logic would need to be changed to support searching multiple directories for binaries. |
Is running a command in a conda env with full path, strictly equivalent to activating the conda environment and then using the command without full path ?
|
…ngle `bin`. `command.run` and `which` both have their `path` argument renamed `paths` and supporting a list of paths, to handle it. Fixes wntrblm#256
I assumed so, but I don't know the answer for sure. |
…ound was not the correct one (#310) * Virtual environments now have a `bin_paths` attribute instead of a single `bin`. `command.run` and `which` both have their `path` argument renamed `paths` and supporting a list of paths, to handle it. Fixes #256 * Updated tests to handle the `paths` renaming of the `path` argument in `nox.command.run`, and the `bin` to `bin_paths` renaming in `virtualenv` * First conda test on windows * Black-ened code * As per code review: Added a backwards-compatible `session.bin` property * Fixed lint error * Added back `bin` to all envs for compatibility with legacy api Co-authored-by: Sylvain MARIE <sylvain.marie@se.com>
Describe the bug
session.run('python', ..., ....)
can not find the virtual environments python.How to reproduce
Here is my noxfile.py. The last line is the where the issue occurs. There are no issues in creating a conda environment, installing conda packages, installing pip packages, and performing the pytest. I have verified it all and it completely works as expected (installing and using binaries and scripts in the virtual environment). The issue is only the last command which could only find a default python on the system (external). I have diagnosed the issue and it is explained below.
Fix
The issue is here: https://github.com/theacodes/nox/blob/ac0992332a266f85152db8a5252b1fdf9818eb75/nox/command.py#L82
where
cmd
ispython
andpath
will be to the virtual environmentsScript
directory. Here is a picture of whatpath
is:As you can see there is no python here. The correct python is here:
The change I performed to fix this issue is highlighted in the images. I changed this:
https://github.com/theacodes/nox/blob/ac0992332a266f85152db8a5252b1fdf9818eb75/nox/command.py#L36
to this:
Now everything works as expected. I am not sure if this is the best way to fix but it works well for me. If this is acceptable I can do a pull request if you would like.
Thanks for your great work!
The text was updated successfully, but these errors were encountered: