Lately I started working with Q# and python as host language. I was working on a project and everything seemed fine. Suddenly I get the error "module not found" and I seem to get it in all my previous projects too.
So I have a directory: C:\Users\Username\Q#projects In this folder I have 2 files: HostProtocol.py, which is the main file, and BB84.qs, which is the file from which I want to import.
The HostProtocol.py file looks like this:
import qsharp
from Quantum.BB84 import Run_BB84Protocol
Run_BB84Protocol.simulate()
The BB84.qs file looks like this:
namespace Quantum.BB84 {
open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
function Run_BB84Protocol() Unit{... the code from the function...}
}
When I try to run HostProtocol.py I get the following error message:
Exception has occurred: ModuleNotFoundError No module named 'Quantum' File "C:\Users\Username\Q#projects\HostProtocol.py", line 3, in from Quantum.BB84 import Run_BB84Protocol
And this is for all my previous projects too. It's very frustrating and I have no clue what could have caused it because it worked fine previously. Any help is definitely welcome!
If you have any Q# compilation errors in your Q# source file, your Q# operations and functions will not be available. Check your Python output for errors. When I run the sample code you provided, it reports a syntax error in the Q# code (there's a missing colon before the return type Unit
):
fail: Microsoft.Quantum.IQSharp.Workspace[0]
QS3211: Invalid return type annotation. The argument tuple needs to be followed
by a colon and the return type of the callable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.