-
Notifications
You must be signed in to change notification settings - Fork 983
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
pytest .
fails to find cirq
module after setting up Cirq dev environment
#5713
Comments
pytest .
fails after setting up Cirq dev environmentpytest .
fails to find cirq
module after setting up Cirq dev environment
Additional info: the underlying problem is that the Python module search path hasn't been set up to search in the right locations for the Cirq modules in the local source directory (or at least, the instructions as written don't tell the user to do anything that would set it up). Here are 3 options for solutions that I can think of.
Out of all of these, I think option 1 might be the safest, but option 2 might have some advantages. People more experienced with Cirq would perhaps have more insight into this. I'd be happy to do a PR if someone can indicate which option is preferred. |
Did you run the |
Yeah, that will also work, but please note that the docs at https://quantumai.google/cirq/dev/development#setting_up_an_environment tell you to run (But I guess that points to a 4th option: switch the order of the instructions in the docs, so that people are told to munge the paths first. In that case, if the order is switched and |
Yeah, this clearly needs to be improved. I would suggest reordering the steps for now, though in the longer term it would be nice to avoid relying on |
I only now noticed something else in the docs: the first alternative given in step 5 in https://quantumai.google/cirq/dev/development#setting_up_an_environment is slightly wrong. You can't simply do
in a shell because what
i.e., using the Bash/sh "." alias for "source", which is equivalent to
That is surely how |
Oh that latter one is definitely me typing it in wrong! |
It's so freakin' easy to do. (And seriously, whoever thought "." would be a good idea for a command?) |
So |
|
My $0.02 is that in this specific context, using However, note that because it's a Bash shell script, it probably won't work for Windows users. (But then, neither will telling people to do something like |
I don't think the changed-files one is correct as this is when setting up a new dev environment, right? So there are no changed files. |
Yes, exactly, which is why I think |
Following the discussion in issue quantumlib#5713, this 3-line PR changes the text in https://quantumai.google/cirq/dev/development to avoid two problems: 1) In step 3 under "Setting up an environment", the `pytest .` command will fail to find the `cirq` package because the instructions up to that point haven't told the user to do anything to their Python environment or search path to enable `pytest` to find the Cirq packages. The discussion around issue quantumlib#5713 seemed to settle on telling people to run `check/pytest` instead of running `pytest` directly. While it's true that it takes a long time to run, in this context it's probably not a bad idea to tell users to run the full tests, and using `check/pytest` is more future-proof in case other special things need to be done in the future. 2) In step 4 of the same page, it says to run `./dev_tools/pypath` in the user's shell, but that's evidently a typo as written, because `pypath` only sets environment variables and so merely executing the script won't change the variables in the user's shell. The text _probably_ meant to say `. dev_tools/pypath`, i.e., to use the shell '.' command to source the file. In the changes in this PR, I propose instead to tell people to use `source dev_tools/pypath` explicitly, because IMHO that's a little less prone to typos and a little more obvious. There is one more change in this PR, which is to change another command line near the bottom of the page to use the path `./dev_tools/....` instead of `dev_tools/....`, so that it's consistent with the style of the other commands given elsewhere on the page.
…mlib#5772) Following the discussion in issue quantumlib#5713, this 3-line PR changes the text in https://quantumai.google/cirq/dev/development to avoid two problems: 1) In step 3 under "Setting up an environment", the `pytest .` command will fail to find the `cirq` package because the instructions up to that point haven't told the user to do anything to their Python environment or search path to enable `pytest` to find the Cirq packages. The discussion around issue quantumlib#5713 seemed to settle on telling people to run `check/pytest` instead of running `pytest` directly. While it's true that it takes a long time to run, in this context it's probably not a bad idea to tell users to run the full tests, and using `check/pytest` is more future-proof in case other special things need to be done in the future. 2) In step 4 of the same page, it says to run `./dev_tools/pypath` in the user's shell, but that won't actually work because `pypath` only sets environment variables and so merely executing the script won't change the variables in the user's shell. The given command evidently has a typo as written; the text _probably_ meant to say `. dev_tools/pypath`, i.e., to use the shell `.` command to source the file. In the changes in this PR, I propose instead to tell people to use `source dev_tools/pypath` explicitly, because IMHO that's a little less prone to typos and a little more obvious. There is one more change in this PR, which is to change another (unrelated to the above) command line near the bottom of the page to use the path `./dev_tools/...` instead of `dev_tools/...`, so that it's consistent with the style of the other commands given elsewhere on the page.
Description of the issue
The instructions at https://quantumai.google/cirq/dev/development#setting_up_an_environment describe how to set up how to clone the repo, install dependencies, set up a virtual environment, and then (in step 4) run
pytest .
from theCirq
subdirectory. When I do this in a relatively plain installation of Ubuntu 20.04 (which is based on Debian), it produces the following error:I realize that Ubuntu is not straight Debian, and the instructions do say they're intended for Debian. However, the same error happens when I try everything in a completely different Python environment (namely on my regular macOS 10.15.6 machine, with a Python 3.9 installed using HomeBrew and
virtualenv
to create the necessary virtual environment), which suggests this is probably not due to Ubuntu vs straight Debian but rather a real underlying problem.How to reproduce the issue
I followed the instructions at https://quantumai.google/cirq/dev/development as closely as possible to use a fresh clone of the current Cirq repo, a relatively clean Ubuntu 20.04 VM running in Parallels on macOS (I say "relatively clean" because I had to install things like
curl
,emacs
, and a few other thing on top of the vanilla Ubuntu 20.04, to make it usable for me). Referring to the steps 1-4 described at https://quantumai.google/cirq/dev/development#setting_up_an_environment, if I follow them through, upon step 4,the error described above occurs. For reference, the folded details section below contains an entire trace of what happens for steps 3 and 4.
Cirq version
0.16.0.dev
The text was updated successfully, but these errors were encountered: