-
-
Notifications
You must be signed in to change notification settings - Fork 161
Virtual environments created by nox fail to inherit the correct version of Python #634
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
Comments
Hey @barbaricyawps thanks for raising an issue! Unfortunately I can't replicate the issue locally even after following the steps to the letter (see below) I'm not sure what could be causing this to be honest, potentially some sort of quirk with WSL? I'm on a mac using python 3.10.4.
On this specifically, you want the following: session.run("your", "command", "args", external=True) The auto release recipe in the Nox cookbook shows some example usage |
Ah, well. That's good to know. Thanks for trying! I'll close the issue. |
More than happy to keep it open if it's genuinely a bug I'm just not sure as I don't have the setup to replicate locally. On the Is it anything to do with simply requiring python3? @nox.session(python="3")
def docs(session) -> None: Might be worth trying a specific version but again I'm not sure if that will actually help. |
Hello! Just wanted to give an update that I tried setting up a brand new WSL and was able to get nox functioning correctly. I suspect this error message I got while installing nox might have something to do with the issues I was having: I followed the directions in the error message to run
|
I'm running up against a problem that looks very similar to this one: I have a minimal example that demonstrates this: # noxfile.py
import nox
@nox.session(python=['3.8', '3.9', '3.10', '3.11', '3.12'])
def test(session):
session.run('python', '--version') $ nox
nox > Running session test-3.8
nox > Creating virtual environment (virtualenv) using python3.8 in .nox/test-3-8
nox > python --version
Python 3.11.1
nox > Session test-3.8 was successful.
nox > Running session test-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/test-3-9
nox > python --version
Python 3.11.1
nox > Session test-3.9 was successful.
nox > Running session test-3.10
nox > Creating virtual environment (virtualenv) using python3.10 in .nox/test-3-10
nox > python --version
Python 3.11.1
nox > Session test-3.10 was successful.
nox > Running session test-3.11
nox > Creating virtual environment (virtualenv) using python3.11 in .nox/test-3-11
nox > python --version
Python 3.11.1
nox > Session test-3.11 was successful.
nox > Running session test-3.12
nox > Missing interpreters will error by default on CI systems.
nox > Session test-3.12 skipped: Python interpreter 3.12 not found.
nox > Ran multiple sessions:
nox > * test-3.8: success
nox > * test-3.9: success
nox > * test-3.10: success
nox > * test-3.11: success
nox > * test-3.12: skipped Every run there appears to be using Python 3.11.1, even when it should be a different minor version.
$ python3.8 --version
Python 3.8.16
$ python3.9 --version
Python 3.9.16
$ python3.10 --version
Python 3.10.9
$ python3.11 --version
Python 3.11.1
$ python3.12 --version
zsh: command not found: python3.12 I'm on macOS 13.3.1, I have $ python3 --version
Python 3.11.1
$ nox --version
2023.4.22
$ pipx list
...
package nox 2023.4.22, installed using Python 3.11.1
- nox
- tox-to-nox EDIT: the context of the $ exa -TL3 .nox
.nox
├── test-3-8
│ ├── bin
│ │ ├── activate
│ │ ├── activate.csh
│ │ ├── activate.fish
│ │ ├── activate.nu
│ │ ├── activate.ps1
│ │ ├── activate_this.py
│ │ ├── pip
│ │ ├── pip-3.11
│ │ ├── pip3
│ │ ├── pip3.11
│ │ ├── python -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
│ │ ├── python3 -> python
│ │ ├── python3.11 -> python
│ │ ├── wheel
│ │ ├── wheel-3.11
│ │ ├── wheel3
│ │ └── wheel3.11
│ ├── lib
│ │ └── python3.11
│ └── pyvenv.cfg
├── test-3-9
│ ├── bin
│ │ ├── activate
│ │ ├── activate.csh
│ │ ├── activate.fish
│ │ ├── activate.nu
│ │ ├── activate.ps1
│ │ ├── activate_this.py
│ │ ├── pip
│ │ ├── pip-3.11
│ │ ├── pip3
│ │ ├── pip3.11
│ │ ├── python -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
│ │ ├── python3 -> python
│ │ ├── python3.11 -> python
│ │ ├── wheel
│ │ ├── wheel-3.11
│ │ ├── wheel3
│ │ └── wheel3.11
│ ├── lib
│ │ └── python3.11
│ └── pyvenv.cfg
├── test-3-10
│ ├── bin
│ │ ├── activate
│ │ ├── activate.csh
│ │ ├── activate.fish
│ │ ├── activate.nu
│ │ ├── activate.ps1
│ │ ├── activate_this.py
│ │ ├── pip
│ │ ├── pip-3.11
│ │ ├── pip3
│ │ ├── pip3.11
│ │ ├── python -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
│ │ ├── python3 -> python
│ │ ├── python3.11 -> python
│ │ ├── wheel
│ │ ├── wheel-3.11
│ │ ├── wheel3
│ │ └── wheel3.11
│ ├── lib
│ │ └── python3.11
│ └── pyvenv.cfg
└── test-3-11
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate.nu
│ ├── activate.ps1
│ ├── activate_this.py
│ ├── pip
│ ├── pip-3.11
│ ├── pip3
│ ├── pip3.11
│ ├── python -> /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
│ ├── python3 -> python
│ ├── python3.11 -> python
│ ├── wheel
│ ├── wheel-3.11
│ ├── wheel3
│ └── wheel3.11
├── lib
│ └── python3.11
└── pyvenv.cfg |
I have tracked down my problem: I have Sorry for the noise! |
Current Behavior
Hi, I'm from the Salt Project. I've had multiple issues trying to use nox to build Sphinx documentation. Typically, when I run a command like
nox -e docs
or similar, I encounter an error like this (I'm using a WSL):FYI, I'm working in the salt-reference-docs, which is where the project name comes from.
Running
python --version
shows the system-level Python (Python 10 in my case).The error seems to be related to how nox interacts with virtual environments such as
venv
andpyenv
. (I have problems with both equally when using nox.) My best guess is that nox activates these virtual environments incorrectly. When these virtual environments activate, they get added to the end of the PATH rather than to the beginning, so it finds the system Python first. That defeats the purpose of using a virtual environment where you can run different versions of Python.Expected Behavior
The virtual environment used by nox should load the correct version of Python by inheriting it from the virtual environment.
Steps To Reproduce
I've recently experienced this on a new Salt documentation repo we set up using the same setup we use on most of our other projects and repos. To reproduce it:
nox -e 'docs-html(clean=False)'
ornox -e docs
.Environment
Workarounds
One workaround seems to be to manually start the virtual environment activation process so that it loads into the PATH correctly.
Another less-than-ideal workaround seems to be to copy the
bin
file from an existing virtual environment from another project where it works and put it inside the virtual environment being used by the current project. This is less than ideal because it messes up any custom CSS I've been working with locally.By the way, I have no idea how to
Pass external=True into run()
like the error message suggests. Perhaps a better-written, more actionable error message or some more supporting documentation would help. Is that something that needs to be passed in when running the nox command to build the docs or is it something in the nox configuration file?The text was updated successfully, but these errors were encountered: