I'm pretty new to Python, but have Python 3.6 installed, and running a few other programs perfectly. I'm trying to pull data using the pandas_datareader module but keep running into this issue. Operating system: OSX.I've visited the other threads on similar errors and tried their methods to no avail.
Additional concern: When using Sublime Text, if I run it as a Python (instead of Python3) build, it funcitons fine, but all my other accompanying programs are written on Python3. Is there a way of making this work on 3.6 that I'm missing?
I have already visited the 'is_list_like' error question, and have changed the fred.py file to pandas.api.types in the import line.
Traceback (most recent call last):
File
"/Users/scottgolightly/Desktop/python_work/data_read_practice.py", line
3, in <module>
import pandas_datareader.data as web
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas_datareader/data.py", line 14, in <module>
from pandas_datareader.fred import FredReader
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas_datareader/fred.py", line 1, in <module>
from pandas.core.common import is_list_like
ImportError: cannot import name 'is_list_like'
As has been noted, is_list_like has been moved from pandas.core.common to pandas.api.types.
There are several paths forward for you.
My (highly) recommended solution: download Conda and set up an environment with a version of Pandas prior to v0.23.0.
You can install the development version of Pandas, with a patch in place:
pip install git+https://github.com/pydata/pandas-datareader.git
Since you say that you have a version of Pandas in a different environment that works, I suspect the Python calling it is version 2.X. If so, try using past.autotranslate to import the older version of Pandas.
If this working version of Pandas actually belongs to a Python 3.X site-packages, then you can manually import it using:
sys.path.insert(0, '/path/to/other/pandas')
Small workaround is to define it like this:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader
Related
I'm trying to import autograd with the following line of code:
import autograd.numpy as np
However, I'm getting the following error when trying to run the script:
Traceback (most recent call last):
File "autograd.py", line 1, in <module>
import autograd.numpy as np
File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
I've tried installing autograd through pip, pip3 and conda, but the error remains the same.
The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.
aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".
Running a locust (locust.io) script from the command line.
locust calls main.py which has the following imports:
from locust import HttpUser, between, task
from StreamLoader.stream_generator import * # thought this brings in everything
Packer.py has these imports:
from multipledispatch import dispatch
from PackedItem import PackedItem
StreamGenerator.py has:
import hashlib
from StreamLoader.Packer import Packer
from aes_encryption import AesEncryption
I used pip to install multipledispatch and when I run from within PyCharm it works fine, but from the command line I get the following.
File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
from StreamLoader.stream_generator import *
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
from StreamLoader.Packer import Packer
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\Packer.py", line 1, in <module>
from multipledispatch import dispatch
ModuleNotFoundError: No module named 'multipledispatch'
Here is what I have tried so far:
Add directories to the PYTHONPATH environment variable
Add empty __init__.py files in each package
This all seems unnecessary if I actually pip installed the module, though.
Answer below caused me to no longer see the error with multipledispatch. However, I now see a missing module error:
File "C:\Users\guyl\PycharmProjects\engine-load-tests\engine_load_tester_locust\main.py", line 2, in <module>
from StreamLoader.stream_generator import *
File "C:\Users\guyl\PycharmProjects\engine-load-tests\StreamLoader\stream_generator.py", line 2, in <module>
from Packer import Packer
ModuleNotFoundError: No module named 'Packer'
For clarity, I am running the code from locust which calls the Python code as depicted here. [Moderators - this question is getting quite long. Is that all right?]
PyCharm uses the virtual environment automatically but when you run from the command line the virtual environment isn't turned on.
Just follow the steps:
cd your_working_directory
environment_name/Scripts/activate if on Windows where environment_name is the name of the PyCharm virtual environment
Or environment_name/bin/activate if on MacOS
-------------EDIT------------------------
To answer the new question, try using pip freeze then see which packages are installed. Then install any dependencies which you want which are missing.
I am unable to run a python script in the command line, and this script works great in Jupyter Notebook and via Anaconda Prompt. This appears to be an issue importing the ssl module during initialization of another module I am importing (mygeotab).
I have googled the error and done as much as I can to diagnose the most common cause which appears to be PATH issues.
I have already diagnosed the PATH to a point, and have added the location of the /lib/ and python.exe to the environment variables. Also, during testing I began my script with the below to protect myself from path issues and printed the path before and after the 'append', which did not have an impact on the problem.
import sys
print(sys.path)
sys.path.append('C:\\Users\\xxxxxx\\Python Scripts')
sys.path.append('C:\\Anaconda3\\python37.zip')
sys.path.append('C:\\Anaconda3\\DLLs')
sys.path.append('C:\\Anaconda3\\lib')
sys.path.append('C:\\Anaconda3')
sys.path.append('C:\\Anaconda3\\lib\\site-packages')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\win32')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\win32\\lib')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\Pythonwin')
sys.path.append('C:\\Anaconda3\\lib\\site-packages\\IPython\\extensions')
sys.path.append('C:\\Users\\xxxxxx\\.ipython')
sys.path.append('C:\\Anaconda3\\Lib')
sys.path.append('C:\\Anaconda3\\Lib\\site-packages')
print(sys.path)
import mygeotab
import pandas as pd
import pyodbc as py
from mygeotab.ext import feed
import sqlalchemy
from time import sleep
However, when I attempt to run the script via the standard command line, I get the below error:
Traceback (most recent call last):
File "PYTHON_GEOTAB_TRIP_FEED.py", line 33, in <module>
import mygeotab
File "C:\Anaconda3\lib\site-packages\mygeotab\__init__.py", line 9, in <module>
from .api import Credentials
File "C:\Anaconda3\lib\site-packages\mygeotab\api.py", line 14, in <module>
import ssl
File "C:\Anaconda3\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
The mygeotab module and ssl.py are both in the locations designated in the Traceback. '_ssl' is the only reference I can not seem to diagnose. Again, this works fine in both Notebook and Anaconda Prompt.
Any ideas?
Windows Server 2008 R2
Anaconda 2019.07 x64
Python 3.7.3 x64
This was solved for me by installing a separate instance of Python 3.7, moving the PATH references and other pointers. I installed pip, mygeotab, and the other packages into the native Python 3.7 instance. It just appears you can't use the one baked into anaconda the way I thought. Thanks for the help everyone.
I wrote a python script over the summer that uses NumPy and Pandas to help me code some corpus data for the linguistics/psych lab I work in. All was fine until I upgraded to OSX Mavericks -- since then the script throws the following ImportError:
No module named dateutil.parser
Traceback (most recent call last):
File "/Users/nicholasmoores/Documents/Research/DataFrame_by_child1.9.2.py", line 30, in <module>
import pandas as pd #you will have to go through the potentially arduous process
File "/Library/Python/2.7/site-packages/pandas-0.11.0-py2.7-macosx-10.8-intel.egg/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 31, in init pandas.tslib (pandas/tslib.c:48027)
ImportError: No module named dateutil.parser
logout
which is quite frustrating! I don't know why anything else on the script would fail to work after dealing with my imports, and numpy and pandas were the only ones I was expecting to have trouble with after upgrading... FYI I'm now running Python 2.7.6
import os.path
import re
import sys
import nltk
import pickle
import numpy as np
import pandas as pd
from nltk.corpus.reader import CHILDESCorpusReader
from nltk.probability import ConditionalFreqDist, FreqDist
fd = FreqDist()
cfd = ConditionalFreqDist()
I'm sure it has to do with OSX's inhouse python getting upgraded and I suppose Pandas is trying to look for python syntax in the dateutil module that has since changed or something like that. If anyone has any suggestions they would be much appreciated as I was hoping to get a lot of data coded over the holidays!
Dateutil is a dependency of pandas, it looks like somehow this module is no longer on your system.
You'll need to (re)install dateutil:
sudo pip install dateutil
What ended up fixing the problem was redownloading and reinstalling dateutil. I'm still not completely sure where the fault was that caused Pandas to not be able to access it anymore, but I'm glad I got it all working again!
I'm on OSX Snow Leopard and I run 2.7 in my scripts and the interpreter seems to be running 2.6
Before I was able to import numpy but then I would get an error when trying to import matplotlib so I went looking for a solution and updated my PYTHONPATH variable, but I think I did it incorrectly and have now simply screwed everything up.
This is what I get when I try and import numpy in my script:
Traceback (most recent call last):
File "./hh_main.py", line 5, in
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/init.py", line 137, in
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/add_newdocs.py", line 9, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/lib/init.py", line 4, in
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/lib/type_check.py", line 8, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/core/init.py", line 5, in
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/core/multiarray.so, 2): Symbol not found: _PyCapsule_Import
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/core/multiarray.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site->packages/numpy/core/multiarray.so
Furthermore this is what I get from sys.path in the interpreter:
['', '/Users/joshuaschneier/Documents/python_files', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload']
And this is my PYTHONPATH which I guess I updated wrong:
:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Thanks for any help.
You'll generally need to install numpy, matplotlib etc once for every version of python you use, as it will install itself to the specific 'python2.x/site-packages' directory.
Is the above output generated from a 2.6 or 2.7 session? If it's a 2.6 session, then yes, pointing your PYTHONPATH at 2.7 won't work - numpy includes compiled C code (e.g. the multiarray.so file) which will have been built against a specific version of python.
If you don't fancy maintaining two sets of packages, I'd recommend installing numpy, matplotlib etc all for version 2.7, removing that PYTHONPATH setting, and making sure that both scripts and interpreter sessions use version 2.7.
If you want to keep both versions you'll just have to install each packages twice (and you'll probably still wnat to undo your PTYHONPATH change)