Posts: 25
Threads: 6
Joined: Jan 2019
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
Posts: 11,872
Threads: 474
Joined: Sep 2016
Feb-01-2019, 10:20 AM
(This post was last modified: Feb-01-2019, 10:20 AM by Larz60+.)
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/
Posts: 25
Threads: 6
Joined: Jan 2019
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
Posts: 11,872
Threads: 474
Joined: Sep 2016
Feb-01-2019, 12:07 PM
(This post was last modified: Feb-01-2019, 12:08 PM by Larz60+.)
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
Posts: 8,090
Threads: 154
Joined: Sep 2016
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.
Posts: 7,081
Threads: 122
Joined: Sep 2016
Feb-01-2019, 05:52 PM
(This post was last modified: Feb-01-2019, 05:52 PM by snippsat.)
(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()
Posts: 25
Threads: 6
Joined: Jan 2019
Feb-02-2019, 04:50 AM
(This post was last modified: Feb-02-2019, 06:22 AM by buran.)
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))
Posts: 8,090
Threads: 154
Joined: Sep 2016
import pandas_datareader.data as web should be
from pandas_datareader import data as web Check the docs
Posts: 25
Threads: 6
Joined: Jan 2019
Feb-02-2019, 06:20 AM
(This post was last modified: Feb-02-2019, 06:24 AM by buran.)
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
Posts: 7,081
Threads: 122
Joined: Sep 2016
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
|