Off topic:try import if not, install in python
0
0
Entering edit mode
4.4 years ago
flogin ▴ 280

I'm trying to install automatically each library in python if it isn't installed.

#!/usr/bin/python
# -*- coding: utf-8 -*-

from pip._internal import main
pkgs = ['Bio==0.1.0','argparse==1.4.0']
for package in pkgs:
    try:
        import package
    except ImportError:
        main(['install', package])

But, this error occurs:

> Collecting Bio==0.1.0   Using cached
> https://files.pythonhosted.org/packages/14/c2/43663d53b93ef7b4d42cd3550631552887f36db02c0150d803c69ba636a6/bio-0.1.0-py2.py3-none-any.whl
> Installing collected packages: Bio Successfully installed Bio-0.1.0
> Collecting argparse==1.4.0   Using cached
> https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl
> ERROR: Could not install packages due to an EnvironmentError: [Errno2] No such file or directory: '/tmp/pip-req-tracker-6sqtap8q/139713c65f8ac559a034717470dc5a6e30a6db86bdc3d69fe2bc0e63'

I notice that this occur always after the first library installation, e.g.: If I change ['Bio','argparse'] for ['argparse','Bio'], the argparse will be installed, and the Bio not.

python install • 1.2k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1803 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6