简体   繁体   English

导入 qsharp ModuleNotFoundError: 没有名为“qsharp”的模块

[英]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.我使用pip install pythonnet安装了名为Python.NET包的python库,安装并导入了clr模块,独立安装qsharp模块成功但导入qsharp显示错误。 Can anyone tell me why it is giving error while importing?谁能告诉我为什么导入时出错?

I am using spyder to run python code and anaconda for installation.我正在使用 spyder 运行 python 代码和 anaconda 进行安装。

The process for installing qsharp is a little convoluted as you have to "install" it more than once.安装 qsharp 的过程有点复杂,因为您必须多次“安装”它。

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.之后它应该在 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 :你必须小心你使用的 Python 版本,如果你的计算机上有很多版本,请删除它们,只让最新的一个,但是 Q# 安装分两步:

Installing package :安装包:

pip install qshart

Then installing kernel ( you'll need to install dotnet ) :然后安装内核(您需要安装 dotnet ):

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

I was using VScode and getting this error very frequently.我正在使用 VScode 并经常收到此错误。 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.我意识到我需要将环境更改为安装 qsharp 的环境..因为它需要安装在与 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.刚刚发布,因为我很早就为此而挣扎。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 qsharp 和 python:从控制台中删除“正在准备 qsharp 环境”消息 - qsharp and python: remove 'preparing qsharp environment' message from console 导入模块:ModuleNotFoundError:没有模块命名 - Import Module : ModuleNotFoundError: No module named Scrapy ModuleNotFoundError:没有名为“import”的模块 - Scrapy ModuleNotFoundError: No module named "import" scrapy import itemloaders ModuleNotFoundError:没有名为“itemloaders”的模块 - scrapy import itemloaders ModuleNotFoundError: No module named 'itemloaders' 无法导入pyLDAvis-ModuleNotFoundError:没有名为“ _contextvars”的模块 - cannot import pyLDAvis - ModuleNotFoundError: No module named '_contextvars' 导入错误-ModuleNotFoundError:没有名为“模型”的模块 - Import error - ModuleNotFoundError: No module named 'model' 导入 talib --- ModuleNotFoundError: 没有名为“talib”的模块 - import talib --- ModuleNotFoundError: No module named 'talib' ModuleNotFoundError: 没有名为“import_export”的模块 - ModuleNotFoundError: No module named 'import_export' 导入 sqlparse ModuleNotFoundError:没有名为“sqlparse”的模块 - import sqlparse ModuleNotFoundError: No module named 'sqlparse' 导入 pyHook。 ModuleNotFoundError:没有名为“pyHook”的模块 - import pyHook. ModuleNotFoundError: No module named 'pyHook'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM