Install Python Mac Terminal


Learn how to install the Quantum Development Kit (QDK) to develop Python host programs that call Q# operations.

Install the qsharp Python package

Installing Packages¶. This section covers the basics of how to install Python packages. It’s important to note that the term “package” in this context is being used to describe a bundle of software to be installed (i.e. As a synonym for a distribution). Import module works in Terminal but not in IDLE. When using python in IDLE on Mac, each python installation has it’s own /lib/site-packages for 3rd party modules. Depending on your installation method (using the regular pip install package-name) terminal won’t allow you to import them when using IDLE. Feb 01, 2021 Install VS Code (Windows, Linux and Mac). Install the QDK extension for VS Code. VS Code also offers its own terminal from which you can run code. If you are using conda, make sure you follow the procedure detailed in the installation section to initialize conda for the shell used by VS Code.

Verifying Python is Installed on Mac. To verify that Python is installed on your macOS device, you will need to start by opening up a terminal session. Within this terminal session, go ahead and run the following command. This command will get Python 3 to return its version number.

The qsharp Python package, which includes the IQ# kernel, contains the necessary functionality for compiling and simulating Q# operations from a regular Python program.

  1. Install Miniconda or Anaconda. Consult their installation guide if you are unsure about any steps. Note: 64-bit installation required.

  2. Initialize conda for your preferred shell with the conda init initialization command. The steps below are tailored to your operating system:

    (Windows) Open an Anaconda Prompt by searching for it in the start menu. Then run the initialization command for your shell, e.g. conda init powershell cmd.exe will set up both the Windows PowerShell and Command Prompt for you. You can then close this prompt.


    To work with PowerShell, conda will configure a startup script to run whenever you launch a PowerShell instance. By default, the script's execution will be blocked on Windows, and requires modifying the PowerShell execution policy with the following command (executed from within PowerShell):

    (Linux) If haven't done so during installation, you can still initialize conda now. Open a terminal and navigate to the bin directory inside your selected install location (e.g. /home/ubuntu/miniconda3/bin). Then run the appropriate command for your shell, e.g. ./conda init bash. Close your terminal for the changes to take effect.

  3. From a new terminal, create and activate a new conda environment named qsharp-env with the required packages (including Jupyter Notebook and IQ#) by running the following commands:

  4. Finally, run python -c 'import qsharp' to verify your installation and populate your local package cache with all required QDK components.

  1. Prerequisites:

    • Python 3.6 or later
    • The PIP Python package manager
  2. Install the qsharp package, a Python package that enables interop between Q# and Python.

  3. Install IQ#, a kernel used by Jupyter and Python that provides the core functionality for compiling and running Q# operations.


    If you encounter a permission error in Linux, install the IQ# kernel in user mode instead with dotnet iqsharp install --user.


    If you encounter an error and you just installed .NET, you won't be able to run the dotnet iqsharp install command immediately. Instead, under Windows, open a new terminal window and try again. Under Linux, log out of your session and log back in to try again.If this still doesn't work, try locating the installed dotnet-iqsharp tool (on Windows, dotnet-iqsharp.exe) and running:

    where /path/to/dotnet-iqsharp should be replaced by the absolute path to the dotnet-iqsharp tool in your file system. Typically this will be under .dotnet/tools in your user profile folder.

That's it! You now have both the qsharp Python package and the IQ# kernel for Jupyter, allowing you to compile and run Q# operations from Python and Q# Jupyter Notebooks.

Choose your IDE

While you can use Q# with Python in any IDE, we highly recommend using Visual Studio Code (VS Code) for your Q# + Python applications. With the QDK extension for VS Code you gain access to richer functionality such as warnings, syntax highlighting, project templates, and more.

Install python 2.7 mac terminal

If you would like to use VS Code:

  • Install VS Code (Windows, Linux and Mac).
  • Install the QDK extension for VS Code.

VS Code also offers its own terminal from which you can run code. If you are using conda, make sure you follow the procedure detailed in the installation section to initialize conda for the shell used by VS Code. On Windows, VS Code will use PowerShell unless configured differently. Doing so will allow you to run Q# with Python programs directly from VS Code's integrated terminal, however you can use any terminal of your choice with access to Python. Remember to activate your Q# environment there before running any programs, using conda activate qsharp-env.

If you would like to use a different editor, the instructions so far have you all set.


Write your first Q# program

Now you are ready to verify your qsharp Python package installation by writing a simple Q# program and running it on a quantum simulator.

Install python mac terminal free
  1. Create a minimal Q# operation by creating a file called Operation.qs and adding the following code to it:

  2. In the same folder as Operation.qs, create the following Python program called host.py. This program imports the Q# operationSampleQuantumRandomNumberGenerator() defined in step 1 and runs it on the default simulator with a .simulate() call:

  3. From a terminal with access to your Python/Q# environment created during installation, navigate to your project folder and run the Python host program:

  4. You should see the result of the operation you invoked. In this case, because your operation generates a random result, you will see either 0 or 1 printed on the screen. If you run the program repeatedly, you should see each result approximately half the time.


The Python code is just a normal Python program. You can use any Python environment, including Python-based Jupyter Notebooks, to write the Python program and call Q# operations. The Python program can import Q# operations from any .qs files located in the same folder as the Python code itself.

Install python on mac terminal

Next steps

Install python 3.5 mac terminal

Now that you have tested the Quantum Development Kit in your preferred environment, you can follow this tutorial to write and run your first quantum program.

For more information on how to run Q# programs with Python, see the following articles:


  • how Q# interacts with a Python host program

  • how to run Q# on a local simulator

  • how to run Q# on quantum hardware through Azure Quantum

  • how to first estimate quantum resources required by your program

Most Viewed Posts