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()).trying:
with _ei:
import uvicorn
from fastapi import FastAPI
- Package name is difference from module name
while (_ei := _EI()).trying:
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('..')).trying:
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.0.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for ensure_import-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efab5e470a8e8824ab1b1fc311674e10ad66855da002cb2e65b4ffbf1f0af938 |
|
MD5 | 5742ad2c3dd3f766f34782e80518d018 |
|
BLAKE2b-256 | 61e40beee9c4ad26076bf6fe9b5870a4851bd5d13051e8157e352ff2e7179fe4 |