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.2.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for ensure_import-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73569d44d0d64ab0dd5a77b7cf9cf96b3c696f401fefeb9b5dad46ec776e3d88 |
|
MD5 | 7c3909173e1311bd7dd94a7a8d93503a |
|
BLAKE2b-256 | ea973e448a65a860d598ea0b49efc88d2ee0152aff42436b0d11f651386c0907 |