简体   繁体   中英

import qsharp ModuleNotFoundError: No module named 'qsharp'

I install the python library named Python.NET package using pip install pythonnet, clr module is installed and imported, installation of qsharp module independently is done successfully but importing qsharp is displaying error. Can anyone tell me why it is giving error while importing?

I am using spyder to run python code and anaconda for installation.

The process for installing qsharp is a little convoluted as you have to "install" it more than once.

The first install would be something like:

dotnet tool install -g Microsoft.Quantum.IQSharp    
dotnet iqsharp install

The second install (that trips some of us up) is you then have to also:

pip install qsharp

After that it should import correctly in Python.

Try

pip3 install qsharp

Then

python3 x.py

You have to be careful from the version of Python that you're using , if you have many versions on your computer delete them and let only the most recent one , however Q# is installed in 2 steps :

Installing package :

pip install qshart

Then installing kernel ( you'll need to install dotnet ) :

dotnet tool install -g Microsoft.Quantum.IQSharp    
dotnet iqsharp install

I was using VScode and getting this error very frequently. I realized that i needed to change the environment to the one in which qsharp was installed.. as it needed to be installed in different environment than base. Also you will need to get the terminal to the directory where your code is.

Just posted as I did struggle with this early on.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM