Python Forum
Import Library but Download first?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import Library but Download first?
#1
Hi,

Please help a newbie to understand how to access libraries.

I've practised with some code & used the import 'xxxxx'.

I'm curious to know whether I should have downloaded this library to my PC before I want to run 'import'?

Sorry if that's a dumb question but I got the impression that when you downloaded Python, it would import automatically any library you needed?

I've been getting some errors like "Cannot find 'xxxx' ..."

Can anyone clarify if I should download any Libraries onto my pc I want to use before I include them in the code.

Thanks
Reply
#2
import only loads specified library, and only if built-in or installed.
most can be installed with follow ing command (from command line):
pip install package-name
It wouldn't be practical to install all packages as there are 166,748 available.
you can browse available packages here: https://pypi.org/
Reply
#3
Thanks Larz60+,

So when you're talking about installed, they are the ones that have been downloaded first to the PC?

Apologies for the basic question, but I want to make sure I know how this all works.

I've been trying to use Pandas for example, and got some errors as the code I was given was to run 'Import Pandas ...' without any reference that I should download & install first?

Thanks Peter
Reply
#4
Quote:So when you're talking about installed, they are the ones that have been downloaded first to the PC?
some popular packages have been per-installed with python, such as cvs and os, but not 'downloaded',
they still need to be imported into your program if you need them, but are already part of the python package.
Pandas requires installation as I showed in previous post
pip install pandas
Reply
#5
also, some packages may depend on other packages. Normally (or in most cases) installing the package you need will take care to install also it's dependencies. Of course, depending on your system, this may not always be the case.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Feb-01-2019, 10:27 AM)OscarBoots Wrote: So when you're talking about installed, they are the ones that have been downloaded first to the PC?
There is no download for you all is done automatic,as mention with pip install pandas
Dependencies(basic that pandas need) as @buran mention is now also been taking care with command over.

To show a demo i use virtual environment,so it work as a new install.
See that basic dependencies also get installed numpy, six, python-dateutil, pytz, pandas.
# Check pip the newest is 19.0.1
λ pip -V
pip 19.0.1 from e:\div_code\panda_env\lib\site-packages\pip (python 3.7)

# Install pandas
(panda_env) E:\div_code\panda_env
λ pip install pandas
Collecting pandas
  Downloading ...
Installing collected packages: numpy, six, python-dateutil, pytz, pandas
Successfully installed numpy-1.16.1 pandas-0.24.0 python-dateutil-2.7.5 pytz-2018.9 six-1.12.0

# Test that that it work
(panda_env) E:\div_code\panda_env
λ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__version__
'0.24.0'
>>> exit()
Reply
#7
Thanks Larz60+, snippsat & buran for your help.

I'm using Anaconda & have found that I have installed pandas & matplotlib.

While practising, with the below code, I found that I have also been able to import them to use.

I do however, get an error about pandas_datareader.

I'm using Python 3.7, is pandas_datareader correct as a library to import??

ModuleNotFoundError: No module named 'pandas_datareader'

import datetime as dt
import matplotlib.pyplot as plt  # shows yellow triangle "Imported but unused"
from matplotlib import style
import pandas as pd              # shows yellow triangle "Imported but unused"
import pandas_datareader.data as web

style.use('ggplot')

start = dt.datetime(2000,1,1)
end = dt.datetime(2016,12,31)

df = web.DataReader('TSLA', 'yahoo', start, end)
print(df.head(4))
Reply
#8
import pandas_datareader.data as web
should be

from pandas_datareader import data as web
Check the docs
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
Hi Again,

I've been able to run the below script after I downloaded & installed Anacaonda and it looks like I have everything.

Happy Days!

]
 
# Python version
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
And here's the result

Output:
Python: 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] scipy: 1.1.0 numpy: 1.15.4 matplotlib: 3.0.2 pandas: 0.23.4 sklearn: 0.20.1
Reply
#10
For Anaconda3 look at Anaconda and other ways to run Python.
pandas-datareader dos not comes with Anaconda3,you install with.
pip install pandas-datareader
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,487 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  download with internet download manager coral_raha 0 2,880 Jul-18-2021, 03:11 PM
Last Post: coral_raha
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,064 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  Regarding import library in two different program file Rohit 3 2,408 Jan-22-2020, 07:14 AM
Last Post: buran
  sys library and how to import using conda michavardy 0 2,464 Feb-26-2019, 08:25 AM
Last Post: michavardy
  Do you know how to import Python Standard Library sylas 30 13,967 Jan-26-2018, 01:32 PM
Last Post: metulburr
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,740 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020