Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import installed Python module?

I've just installed a Python package using pip:

$ sudo pip install py_vollib
Password:
Collecting py_vollib
  Downloading py_vollib-1.0.1.tar.gz
Collecting py_lets_be_rational (from py_vollib)
  Downloading py_lets_be_rational-1.0.1.tar.gz
Requirement already satisfied: simplejson in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: numpy in /Library/Python/2.7/site-packages (from py_vollib)
Collecting pandas (from py_vollib)
  Downloading pandas-0.20.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.0MB)
    100% |████████████████████████████████| 15.1MB 54kB/s
Requirement already satisfied: scipy in /Library/Python/2.7/site-packages (from py_vollib)
Requirement already satisfied: pytz>=2011k in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: python-dateutil in /Library/Python/2.7/site-packages (from pandas->py_vollib)
Requirement already satisfied: six>=1.5 in /Library/Python/2.7/site-packages (from python-dateutil->pandas->py_vollib)
Installing collected packages: py-lets-be-rational, pandas, py-vollib
  Running setup.py install for py-lets-be-rational ... done
  Running setup.py install for py-vollib ... done
Successfully installed pandas-0.20.3 py-lets-be-rational-1.0.1 py-vollib-1.0.1

and I've verified it's installed correctly:

$ pip freeze | grep vollib
py-vollib==1.0.1

but I can't import it in Python:

$ python
Python 2.7.13 (default, Jul 20 2017, 18:14:09)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import py_vollib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named py_vollib

Does anybody know what I'm doing wrong here?

[EDIT]

I've checked out help('modules'), which also shows the py_vollib package:

enter image description here

like image 361
kramer65 Avatar asked Nov 08 '22 18:11

kramer65


1 Answers

you are doing sudo pip install py_vollib which is installing the library in your root env.

If you are doing import py_vollib in ipython notebook or something, the module won't be available.

Try sudo python and then do the import

Or

do pip install py_vollib and then do python and try import py_vollib

like image 193
Vikash Singh Avatar answered Nov 15 '22 11:11

Vikash Singh