» pip install stockstats
I got this error out of the box with Anaconda 4.4:
>>> import pandas.io.data
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.6/site-packages/pandas/io/data.py", line 2, in <module>
"The pandas.io.data module is moved to a separate package "
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.
The error message is pretty nice. It recommends you go install pandas-datareader from https://github.com/pydata/pandas-datareader. Then change your import to from pandas_datareader import data.
Or you can just pip install pandas-datareader.
After that, from pandas_datareader import data works as expected:
Matthews-MacBook-Pro:python matt$ python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pandas_datareader import data
>>>
The sub-package pandas.io.data was deprecated in v.0.17 and removed in v.0.19. Instead there has been created a separately installable pandas-datareader package. This will allow the data modules to be independently updated on your pandas installation.
Installing
To install required packages through pip :
pip install pandas-datareader
OR
pip install git+https://github.com/pydata/pandas-datareader.git
Testing
from pandas_datareader import data
df=data.DataReader('AAPL','yahoo','2016/1/1','2017/1/1')
df.head()

Resources
pandas-datareader
Remote Data Access
Your PYTHONPATH is set to the parent directory of the executed script. So if the executed script is inside a directory src, it will never be able to find the sister directory lib because it isn't within the path. There's a few choices;
- Just move
lib/intosrc/if it belongs to your code. If it's an external package, it should be pip installed. - Have a top-level script outside of
src/that imports and runssrc.main. This will add the top-level directory to python path. - In
src/main.pymodifysys.pathto include the top-level directory. This is usually frowned upon. - Invoke
src/main.pyas a module withpython -m src.mainwhich will add the top-level directory to the python path. Kind of annoying to type, plus you'll need to change all your imports.
If I may add to MarkM's answer, if you wanted to keep your current directory structure and still make it work, you could add a setup.py in your root directory, where you can use setuptools to create a package you could install.
If your file had something along the lines of:
# setup.py
from setuptools import find_packages, setup
setup(
name='foo',
version=`1.0.0`,
packages=find_packages(),
entrypoints={
'console_scripts': [
'foo=src.main:main',
],
},
)
And then you do pip install [--user] -e path/to/directory you'll get an "editable package" which will effectively a symbolic link to the package in your development directory, so any changes you make will not require a reinstall (unless of course you rejig package structure or add/remove/edit entry points).
This does assume your src/main.py has a main function.
You'll also need __init__.py files in your "package" directories, even in Python 3, as otherwise Python assumes these are namespace packages (I won't go into detail) and the find_packages() call won't find them.
This will also allow your relative imports to work. Absolute imports will only work when invoking the script from your entry point, but not when calling the script directly in your development directory.
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
Based on your comments to orip's post, I guess this is what happened:
- You edited
__init__.pyon windows. - The windows editor added something non-printing, perhaps a carriage-return (end-of-line in Windows is CR/LF; in unix it is LF only), or perhaps a CTRL-Z (windows end-of-file).
- You used WinSCP to copy the file to your unix box.
- WinSCP thought: "This has something that's not basic text; I'll put a .bin extension to indicate binary data."
- The missing
__init__.py(now called__init__.py.bin) means python doesn't understand toolkit as a package. - You create
__init__.pyin the appropriate directory and everything works... ?
I ran into something very similar when I did this exercise in LPTHW; I could never get Python to recognise that I had files in the directory I was calling from. But I was able to get it to work in the end. What I did, and what I recommend, is to try this:
(NOTE: From your initial post, I am assuming you are using an *NIX-based machine and are running things from the command line, so this advice is tailored to that. Since I run Ubuntu, this is what I did)
Change directory (cd) to the directory above the directory where your files are. In this case, you're trying to run the
mountain.pyfile, and trying to call thetoolkit.interface.pymodule, which are in separate directories. In this case, you would go to the directory that contains paths to both those files (or in other words, the closest directory that the paths of both those files share). Which in this case is thetoolkitdirectory.When you are in the
toolkitdirectory, enter this line of code on your command line:export PYTHONPATH=.This sets your PYTHONPATH to ".", which basically means that your PYTHONPATH will now look for any called files within the directory you are currently in, (and more to the point, in the sub-directory branches of the directory you are in. So it doesn't just look in your current directory, but in all the directories that are in your current directory).
After you've set your PYTHONPATH in the step above, run your module from your current directory (the
toolkitdirectory). Python should now find and load the modules you specified.