简体   繁体   中英

Importing Virtual Environment Installed Packages into Jupyter Notebook

I want to install the google-cloud-bigquery library into my Jupyter Notebooks project (project located within "EDF Boston" directory). I already downloaded- via my command prompt- the "google-cloud-bigquery" library in my activated virtual environment (see code below)

(venv) C:\Users\Joe\Documents\EDF Boston\venv\Scripts>pip install --upgrade google-cloud-bigquery

The following code block I found online as something to run at the beginning of my code to import the google-cloud-bigquery library into my Jupyter Notebook project. However, when I replace "" with "venv" and run the code, I get a syntax error.

!pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-bigquery

I have tried opening a Jupyter Notebook both from within the virtual environment and from outside of it, but can't get it to work either way.

First, you do not need to use venv to run the Python BigQuery API within your Jupyter Notebook. You can install manually each necessary package using pip , as described in the documentation . After installing the packages, inside your Python code use import package_name to use it within your script.

However, I would like to point that venv is used to create an isolated Python environment, which allows you to isolate project dependencies. According to the documentation , it is advisable to use venv when developing locally with Python. In order to use venv, follow the steps below:

  1. Copy your entire Python installation:

    cd your-project python3 -m venv venv

  2. Set your shell to use Venv paths

    source venv/bin/activate

  3. Now install the packages without affecting other environments:

    pip install --upgrade google-cloud-storage

    pip install --upgrade google-cloud-bigquery

  4. If you need to exit the environment:

    deactivate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM