Skip to main content
Chemistry LibreTexts

2: Thonny-Virtual Environments

  • Page ID
    472135
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    Thonny makes it very easy to create virtual environments.  Once you have created a virtual envrionment you can install packages from resources like the python package index. In this module we will show you how to create a virtual environment and install the google spreadsheet Python API gspread package.  First, go to pypi.org and search for gspread, and you see that gspread 6.0.2 was last updated Feb 14, 2024.

    clipboard_e531f2403d67f6ceb70541a930e1bb621.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    when you click on it you see you can install it by running the following pip command on the terminal

    pip install gspread
    

    But when you run it you get the following error message, which essentially says that you must set up a virtual environment (venv) if you want to install an externally managed package. 

    clipboard_e5c44484c80b97f5ed27aa8b15a77b0e9.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    Creating a Virtual Environment

    Create an empty folder - this will be the folder we use for assignment 8 the Google API: ASN8_API

    Open Thonny and choose tools/options

    clipboard_e221bccc57429749d9f09adbe0fe21dbc.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    Go to Interpreter and choose New virtual environment

    clipboard_e617a7b04f1978b68e4edb066f96258e5.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    After clicking OK you need to navigate to your empty folder

    clipboard_e1be7060fad3128996c97802e01568cb5.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    You will probablty need to use the Other locations, although there is a Desktop option if that is where you are keeping your assignments

    clipboard_ecb926efe46e312d3121b5bbfb93eded3.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    click OK, and it will create a virtual environment in that folder

    clipboard_e5e5f385ddebb63c4e2ed333695092517.png

     

    clipboard_e692f2e67a15385be56ffe28bf25b7881.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    now by simply clicking the pyenv.cfg file you will open Thonny with the virtual enterpreter.

    Go to Tools Manage Packages and you can search the PyPi package index from Thonny

    clipboard_e4fcb1b90dbf045aaaca3cab2738eabe2.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

    Chose the package you want and click instal

    clipboard_eaebb930bd07710e0d21bcfba4d71aef1.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

    You now have a virtual environment with the gspread suite and all of its dependencies.

    clipboard_e63fc44796ca6e9c80a9817e6833b82ff.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)

     

     

     

     

     

     


    2: Thonny-Virtual Environments is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?