import qsharp ModuleNotFoundError: No module named 'qsharp' - python

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.

Related

How to fix "Error: No module named mysql.connector"

I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.
I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.
So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.
But Still problem not fixed. Any idea how to fix this?
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python
interpreter it finds in the system path. To select a specific
environment, use the Python: Select Interpreter command from the
Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation:
https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2.
Pip3 is just for python3.
You must use pip2 or pip2.7 for work with python2.
Search if you got the pip2 package installed is not then install it.

Python2.7 no smb module. Cant locate

Running kali 2020, I am trying to run CVE-2007-2447 which is a python2.7 script, which says:
import smb
from smb.SMBConnection import SMBConnection
I saved the script to a file and ran it, but I get ImportError: No module named smb. In the script, it says install pysmb by running pip install --user pysmb.
I did this, but still the same error message.
I tried to locate pysmb and found these packages:
$ locate pysmb
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/PKG-INFO
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/pysmbc-1.0.23.egg-info/top_level.txt
/usr/share/system-config-printer/pysmb.py
/usr/share/system-config-printer/__pycache__/pysmb.cpython-39.pyc
I have had a problem before where packages only install for python3 and I have to copy the folders to python2.7. I tried that for this without success.
When I googled module smb, it comes up with samba. I installed the samba package but still nothing. Does anyone know how I can get smb module to python2.7?
You need to install using the Python 2.7 pip. Use the following command:
pip2.7 install pysmb
Pip no longer supports Python 2.
pip documentation v21.0.1
You need to use python 2 pip to install the module, instead of installing it for python 3. See How to use pip with Python 3.x alongside Python 2.x
.
In my case, the problem was simple.
I named the python script file 'smb.py'. 'smb.py' and'pysmb' were in conflict.

Modules that Have been installed in PIP not appearing in PyCharm via the import function

I have recently started learning Python using PyCharm on Windows 10. I am trying to use PIP to install modules (I have tried Pillow, Pygame and randomword). When I try to install these, PIP says that I was successful and the module comes up when I use Pip freeze. However When I try to import them into Pycharm using the from import function. The module is not found. I cannot locate the module in the LIB folder as well. What do I need to do to have these modules appear in python,
Many Thanks,
Did you make sure you installed the module with the right pip?
I mean, many people with have more than one python editor installed, and so, there will be multiple pips. If you installed a module with the pip from IDLE-3.8, the module will only be installed for that IDLE-3.8.

ModuleNotFoundError: No module named 'Cython'

Why does Cython not want to work ? I've pip installed it and when I try to import it, it just won't work.
I'm using MacOS Version 10.12.6 (16G29)
Here's even a screenshot:
This is possible if you have multiple versions of Python installed try:
python3.7 -m pip install cython
use which pip3 to check where it was installing the package previously
Update: OP used python3.7, if you have a different alias or a different version, you should use that instead. This is obviously installation dependent.

Import Error: No module called magic yet python-magic is installed

I am trying to edit some code that uses python-magic but I get an Import Error: No module called magic. Before I looked around the Internet and found advise on installing python-magic using pip which I did. I installed python-magic using pip install python-magic and also did pip install libarchive-c successfully.
when I try to do the import on the python shell. I am able to successfully as below;
But when I try to run code that uses this import statement I get an import error for missing magic module as below;
If anyone knows what is happening. Please help.
You have installed magic for Python 2.7, but Diffoscope uses Python 3 and explicitly recommends the package python3-magic in the repositories, which can be installed with sudo apt-get install python3-magic. Modules installed for Python 2.7 are not necessarily shared with Python 3, so you may need to install both versions if you need it for 2.7 as well.
On Ubuntu, you can run Python 3 with python3 and access Python 3's pip installation with pip3 to ensure that you are using the correct version.

Categories