Auto install third part packages by pip into virtual environment when import error.
Project description
ensure_import
Auto install third part packages by pip into virtual environment when import error.
Install
pip install ensure_import
Usage
- Simple case that package name is module name
from ensure_import import EnsureImport as _EI
while _ei := _EI():
with _ei:
import uvicorn
from fastapi import FastAPI
- Package name is difference from module name
while _ei := _EI():
with _ei(dotenv='python-dotenv', odbc='pyodbc'):
import numpy as np
import uvicorn
import odbc # who's package name is `pyodbc`
from fastapi import FastAPI
# package name of dotenv is `python-dotenv`
from dotenv import load_dotenv
- Supply module path
while _ei := _EI('..'):
with _ei:
import gunicorn
import uvicorn
This is equal to:
try:
import gunicorn
import uvicorn
except ImportError:
import sys
sys.path.append('..')
import gunicorn
import uvicorn
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ensure_import-0.3.1.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for ensure_import-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46ebc48c27abe080b3543fd252588c40846c96074e7f08e357d9c310d121e610 |
|
MD5 | 9bceb44bbd35b11a06bab47e7e31508d |
|
BLAKE2b-256 | cdf5b669e95c4a5cb35dbec980248f7e0f5c3c63e4019bc5e6cbbc1b1a41db8a |