Jupyter Notebook not finding IQSharp - python

I have been trying to get a Q# running for the Quantum Katas, but have been having some difficulty in finding the Q# kernal. The only kernal that shows up is the Python 3 one which is used for the Jupyter Notebook. The odd thing is that the kernal shows up when I do jupyter kernalspec list.I am using VS Code.
This is the jupyter kernelspec list

Summarizing what was said in the comments above:
First, make sure iqsharp is installed. Run dotnet iqsharp --version to ensure that the tool exists.
If not, run dotnet tool install -g Microsoft.Quantum.IQSharp to install it.
Then run dotnet iqsharp install to register the IQ# kernel in your Jupyter configuration.
If your jupyter installation still doesn't recognize the kernel, it could be a permissions issue based on how you have installed and are running Jupyter. Try dotnet iqsharp install --user instead.
As for VS Code's Jupyter implementation, currently non-Python kernels such as R, Julia, Q#, etc. are not supported. This GitHub issue tracks adding support: https://github.com/microsoft/vscode-python/issues/8521

Related

Why is the module 'ultralytics' not found even after pip installing it in the Python conda environment?

In a conda environment with Python 3.8.15 I did
pip install ultralytics
successfully installed ...,ultralytics-8.0.4
But when running from ultralytics import YOLO , it says
ModuleNotFoundError: No module named 'ultralytics'
I run using Colab.
First I install Ultralytics using pip command
!pip install ultralytics
then
from ultralytics import YOLO
and it worked.
Were you using Jupyter notebook? if so, jupyter might not using the correct python interpreter. Or you're using jupyter that installed on system instead of jupyter installed inside a conda environment.
To check which python jupyter use this code on a cell:
import sys
print(sys.executable)
To list all installed python interpreter available. use this command:
!which -a python
The python inside the conda environment should be on the path something like this:
~/.conda/envs/{myenv}/bin/python
To use correct interpreter inside a conda environment you need to use separate jupyter installation inside the conda environment. see this answer: How to use Jupyter notebooks in a conda environment?
You can use magic %pip install from a cell inside the notebook to insure the installation occurs in the environment that the Jupyter notebook kernel is using. Mikhael's answer points out the thorough way to be really sure how to deal with this and fully control things. However, it is nice to have convenient, quick alternatives when trying to get past a hurdle.
For those using actual Jupyter anywhere (not Google Colab), the install command would be:
%pip install ultralytics
Be sure to let the installation process fully depending on your system and network this can take a bit. Next, after running any magic install command, you'll see a message to restart the kernel, and it is always best to do that before trying the import statement. Finally, after restarting the kernel you can run the suggest import after of from ultralytics import YOLO and hopefully not encounter ModuleNotFoundError: No module named 'ultralytics' now.
The magic command was added to insure that installation occurs in the environment where the kernel backing the notebook is found. See here for more about the modern magic install commands in Jupyter. (For those using conda/Anaconda/mamba as the primary package manager for when packages have conda install recipes, theres a related %conda install variation that also insures installation to the proper environment that the kernel is using.)
See JATIN's answer if you are using Google Colab at this time. Because I don't believe Google Colab has the magic pip install as they have sadly not kept up with current Jupyter abilities.
The exclamation point use in conjunction with pip install is outdated for typical Jupyter given the addition of the magic command. Occasionally, the exclamation point not insuring the the install occurs in the same environment wherein the kernel is running could lead to issues/confusion, and so the magic command was added a few years ago to make installs more convenient. For more about the shortcoming of the exclamation point variant for this particular task, see the first sentence here.
In fact, these days no symbol is better than an exclamation point in front of pip install or conda install when running such commands inside a vanilla Jupyter notebook. No symbol being even better than an exclamation typically now is due to automagics being enabled by default on most Jupyter installations. And so without the symbol, the magic command variant will get used behind-the-scenes. Typically, it is better to be explicit though and use the magic symbol, but you may see no symbol work or be suggested and wonder what is happening.

Select python kernel for Jupyter notebook

This is a basic beginner question.
I have a python Jupyter notebook, when <Enter><Shift> is used, the focus goes to the top of the screen where the message is Select kernel for 'D:/...' Under this is the message: "Install kernels from the marketplace." There is no other visible message to explain what that means or what I am missing.
Steps to solve.
In one document, it mentioned that VSC should be opened using code from a [conda] environment where python is installed and there is a kernel. This required the following code in my environment
activate conda environment edw
conda activate edw
Next install a kernel
ipython kernel install --name "edw" --user
Verify the kernels
jupyter kernelspec list
result
edw C:\Users\hnelson3\AppData\Roaming\jupyter\kernels\edw
Start VSC
code
Next I open a notebook and put my cursor in a code block.
<Enter><Shift>
The message Select kernel for 'D:/...' appears. What is the next step?
Thanks.
I had that message 'Select kernel for 'D:/...' appearing as well when I first tried to run a jupyter notebook in VS code. Turns out I had to install and enable the jupyter extension (https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) and the python extension (https://marketplace.visualstudio.com/items?itemName=ms-python.python) as according to these instructions from https://code.visualstudio.com/learn/educators/notebooks:
"You will need to have Python 3 installed on your machine along with the Microsoft Python extension installed from the VS Code Marketplace...
In addition, you need to install the Jupyter Notebooks extension...
Once you have Python and the extensions installed, you will need to activate the Python environment by using the command Python: Select Interpreter from the Command Palette (Ctrl+Shift+P)."

python3.7 is not able to open jupyter notebook

I have two versions of python in my Macbook, python3.7 and python3.8. I've been using python3.7 to do my data analysis. I used $python3.7 -m jupyter notebook to open jupyter notebook all the time. I've stopped for a while, last week I typed the same command in the terminal, jupyter notebook was opened by python3.8. I tried different ways, seems python3.7 isn't functional at all, jupyter notebook is only able to be opened by python3.8.
I have two questions:
How to open jupyter notebook again with python3.7?
Can I use python3.8 to keep analyzing the data generated in python 3.7? I tried to do some analysis in python3.8, seems it's fine so far, but I'm not sure about it as I'm still a beginner.
Thank you in advance for your nice help!
Yi
Get rid of python3.7 it had known issues. I do not know why your jupyter-notebook stopped working suddenly but you can use python3.8. I doubt that you are using any processes that got deprecated between the two major releases.
I recommend setting up a virtual environment with whatever python version you want:
$ virtualenv --python=python3.7 env/
$ source env/bin/activate
(env) $ pip install ...
This approach avoid any dependencies clashing and isolate you project dependencies from the system ones.

ModuleNotFoundError in Jupyter while pip freeze shows its installed

I created a virtual environment, installed pandas and some other libraries, changed the ipython kernel and then opened jupyter inside my virtual environment. Pandas and other libraries worked fine.
Then i installed fastai in my virtualenv, but it shows ModuleNotFoundError in Jupyter only. It works fine in terminal, when i run !pip freeze inside Jupyter it lists 'fastai', when i try to install it in jupyter with '!pip install fastai' it shows 'Requirement already satisfied' but importing it still gives me 'ModuleNotFoundError'. Check this image for example
All answers on SO to this question are for people who haven't changed their jupyter kernel to their environment or who have had other issues, but i couldn't find my issue.
You have to add the virtualenv to the kernel. Nice discussion is here (Execute Python script within Jupyter notebook using a specific virtualenv).
Assuming virtualenv is working fine (jupyter-notebook and fastai are working), these are the additional steps, I might have tried. In the second line (below) change the "--name=NameOfVirtualEnv" appropriately with the name of your virtualenv.
pip install --user ipykernel
python -m ipykernel install --user --name=NameOfVirtualEnv
After that once you start the Jupyter notebook, you will see the "New" dropdown to the right side .. there you will have your virtual environment with the fastai.
Please let me know the outcome. Curious if it worked for you.

install jupyter notebook in windows

My Python version is 3.6.0 and my operating system is
Windows.
I want to install jupyter notebook using the order pip install jupyter.
But it failed, I got the following error:
Three Ways to Run Jupyter In Windows
The "Pure Python" Way
Make your way over to python.org, download and install the latest version (3.5.1 as of this writing) and make sure that wherever you install it, the directory containing python.exe is in your system PATH environment variable. I like to install it in the root of my C: drive, e.g. C:\Python35, so my PATH contains that directory.
Once that's installed, you'll want to create a virtual environment, a lightweight, disposable, isolated python installation where you can experiment and install 3rd party libraries without affecting your "main" installation. To do this, open up a Powershell window, and enter the following commands (where "myenv" is the name of the virtualenv we're going to create, you can use any name you like for this):
PS C:\> python -m venv myenv
PS C:\> myenv\Scripts\activate
Then, let's install jupyter and start up a notebook:
PS C:\> pip install jupyter
PS C:\> jupyter notebook
Incidentally, if you get a warning about upgrading pip, make sure to use the following incantation to upgrade (to prevent an issue on windows where pip is unable to upgrade its own executable in-place):
PS C:\> python -m pip install --upgrade pip
Advantages: Uses "pure" python, official tools, and no external dependencies. Well supported, with plenty of online documentation and support communities.
Disadvantages: While many popular data analysis or scientific python libraries can be installed by pip on windows (including Pandas and Matplotlib), some (for example SciPy) require a C compiler and the presence of 3rd party C libraries on the system which are difficult to install on Windows.
Who is it for? Python users comfortable with the command line and the tools that ship with Python itself.
The Python Distributions
Because of the difficulty mentioned above in getting packages like SciPy installed on Windows, a few commercial entities have put together pre-packaged Python "distributions" that contain most, if not all, of the commonly used libraries for data analysis and/or scientific computing.
Anaconda is an excellent option for this. Download their Python 3.5 installer for Windows, run it, and in your Start menu you'll have a bunch of neat new tools, including an entry for Jupyter Notebook. Click to start it up and it'll launch in the background and open up your browser to the notebook console. It doesn't get any easier than that.
Advantages: Simplest, fastest way to get started and it comes with probably everything you need for your scientific computing projects. And anything it doesn't ship with you can still instalAl via its built in conda package manager.
Disadvantages: No virtualenv support, although the conda package manager provides very similar functionality with the conda create command. Relies on a commercial 3rd party for support.
Who is it for? People who want the quickest, easiest way to get Jupyter notebook up and running (IE, most people).
Docker
Docker is a platform for running software in "containers", or self-contained, isolated processes. While it may sound similar in concept to python virtual environments, Docker containers are an entirely different kind of technology offering vast flexibility and power. Don't let the flexibility and power and confusing terminology put you off though -- Docker can be easy to get up and running on your PC and has some advantages of its own with respect to Python and Jupyter.
To get started on Windows, download the Docker Toolbox, which contains the tools you need to get up and running. Run the installer and make sure the checkbox to install Virtualbox is checked if you don't already have Virtualbox or another virtualization platform (like VMWare Workstation) installed.
Once installed, you'll have a "Docker Quickstart Terminal" shortcut in your Start Menu. Double click that shortcut and it will create your first Docker engine for you and set up everything you need automatically. Once you see a prompt in the terminal, you can use the docker run command to run Docker "images", which you can think of as pre-packaged bundles of software that will be automatically downloaded from the Docker Hub when you run them. There are many images on Docker Hub that offer Jupyter, including the official Jupyter Notebook image, and Anaconda itself if you want the full SciPy stack.
To run just the official Jupyter Notebook image in your Docker engine, type the following into the Docker Quickstart Terminal:
$ docker run --rm -it -p 8888:8888 -v "$(pwd):/notebooks" jupyter/notebook
After all the image's "layers" are downloaded, it will start up. Make a note of the IP address listed in the terminal (for example, 192.168.99.100), and point your browser at that IP address, port 8888 (e.g. http://192.168.99.100:8888) and you'll see the familiar Jupyter console, with both Python 2 and Python 3 kernels available.
Advantages: Use the flexibility and power of Docker! Honestly one of my favorite things about Docker is thinking of it as an open software distribution platform for things like the SciPy stack that are hard to install.
Disadvantages: Grapple with the flexibility and power of Docker! There are quite a few "gotchas" to be aware of when dealing with Docker, such as immutable containers, data volumes, arcane commands, and rapidly developing, occasionally buggy tooling.
I met the same problem as yours. I updated my Python to version 3.6.1 and re-install Jupyter notebook. I encounter the first problem UnicodeDecodeError when pip setting up tornado, my system is Windows 8.1 64bit.
Here is what I do to solve it:
I open the directory ...\Python\Python36\Lib\site-packages\tornado where new python installed
open the directory ...\Python\Python35\Lib\site-packages\tornado where old python installed
Then I copy and overwrite all *.py files in new tornado directory form old tornado (Note: my old tornado is the latest 4.4.2)
Then I run instruction pip install jupyter notebook again
then the same problem when pip setting up MarkupSafe, I do same as above. This time instruction pip install jupyter notebook do not throw error anymore. And Jupyter notebook works.
I think if you have the old version modules of Jupyter, you can try as what I do, Or think about download the error module manually and place them into right directory.
Hope this can help you.

Categories

Resources