Re: Zephyr escaping its virtual environment

Jason Bens <jason.bens@...>

Hey Marti, thanks for the advice.

In this case specifically, I tracked it down to a pretty silly mistake. I was using the nRF extension for VS Code, but also had the CMake extension installed. I had been hitting the CMake extension's build button, not the nRF extension's, without realizing it was bypassing west. So, an easy enough fix once I realized it.

- Jason

-----Original Message-----
From: Bolivar, Marti <Marti.Bolivar@...>
Sent: Friday, November 12, 2021 6:53 PM
To: Jason Bens <Jason.Bens@...>; users@...
Subject: RE: [Zephyr-users] Zephyr escaping its virtual environment

External Email:


It's hard to diagnose issues like this remotely, and especially with so few details.

If you are looking for general advice:

- check your PATH for where west is installed
- check things like 'py -3 -m pip freeze' inside and outside
your virtual environment to check what is installed where
- uninstall any pythons on your system, making sure you do not have
'west' on your PATH, then reinstalling them

Using Zephyr with a python virtual environment is supported, does work, and is my strong personal recommendation. Unfortunately, if you have been inconsistent about using venvs, it can leave your system in a mixed state that you will need to untangle.

I have been pushing for virtual environments to be the default recommendation in the getting started guide for years, but other maintainers have disagreed with me, and it hasn't happened. Sorry for any inconvenience.


On Fri, Nov 12 2021, Jason Bens wrote:
Hey Marti,

As far as I can tell, I don't have west currently installed outside of the virtual environment. This project I'm trying to get going predates a tonne of build environment issues I've been fixing for the past couple weeks, though. When I first started, there was no venv, and python was on the normal windows path. Could it be that the original path has been stored somewhere and survived the purge?


-----Original Message-----
From: Bolivar, Marti <Marti.Bolivar@...>
Sent: Thursday, November 11, 2021 6:40 PM
To: Jason Bens <Jason.Bens@...>; users@...
Subject: Re: [Zephyr-users] Zephyr escaping its virtual environment

External Email:

Hi, I use zephyr exclusively within virtual environments.

Did you install west outside of the venv? If you build with west, Zephyr tries to use the same python from the build system that you used for running west.

On Thu, Nov 11 2021, Jason Bens via lists zephyrproject org wrote:

I’m trying to build zephyr inside a python virtual environment. It looks like it’s somehow pulling in the base python interpreter, rather than the fake one provided in the virtual environment. This manifests as zephyr\scripts\dts\python-devicetree\src\devicetree\ failing to import yaml (my base python environment is pretty barebones). It looks like the python path is picked up in python.cmake:

foreach(PYTHON_PREFER ${PYTHON_PREFER} ${WEST_PYTHON} "python" "python3")

I haven’t defined PYTHON_PREFER or WEST_PYTHON, and don’t see any documentation suggesting I ought to. I don’t fully understand how find_program is finding the executable, but had assumed it would check my path at some point. I’ve confirmed that .venv\Scripts is the first entry in my path. `where python´ from my virtual environment returns the following:


I’m working with version 2.6.99. Before I file it as an issue, is this something that is fixed in 2.7.99? Is there some known configuration stuff I’m failing to do?


* Jason

Join to automatically receive all group messages.