Import Error: C extension (pandas; python; ubuntu) - python

I am new to Linux and do not know how to fix this error.
$ python googledrive/scripts/test.py
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.5/site-packages/pandas/compat/__init__.py", line 46, in <module>
import __builtin__ as builtins
ImportError: No module named '__builtin__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/michael/anaconda3/lib/python3.5/site-packages/pandas/__init__.py", line 7, in <module>
from pandas import hashtable, tslib, lib
File "pandas/tslib.pyx", line 53, in init pandas.tslib (pandas/tslib.c:102872)
File "/home/michael/anaconda3/lib/python3.5/site-packages/pandas/compat/__init__.py", line 59, in <module>
import http.client as httplib
File "/home/michael/anaconda3/lib/python3.5/http/client.py", line 71, in <module>
import email.parser
File "/home/michael/googledrive/scripts/email.py", line 4, in <module>
import pandas.io.data as web
File "/home/michael/anaconda3/lib/python3.5/site-packages/pandas/io/data.py", line 15, in <module>
from pandas.compat import(
ImportError: cannot import name 'bytes_to_str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "googledrive/scripts/test.py", line 11, in <module>
main()
File "googledrive/scripts/test.py", line 2, in main
import pandas as pd
File "/home/michael/anaconda3/lib/python3.5/site-packages/pandas/__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: 'bytes_to_str' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
Python 3.5.0 :: Anaconda 2.4.0 (64-bit)
I tried conda install -f pandas and it still hasn't fixed my issued.
googledrive/scripts/test.py
def main():
import pandas as pd
import pandas.io.data as web
all_data = {}
all_data['fb'] = web.DataReader('fb','yahoo','1/1/2015', '11/24/2015')
print(all_data['fb'])
I do not know which directory I should run the below suggestion.
python setup.py build_ext --inplace
I don't have any problem running the code line by line in the terminal, but only when I try to run my script file.
>>> print(all_data['fb'])
Open High Low Close Volume \
Date
2015-01-02 78.580002 78.930000 77.699997 78.449997 18177500
2015-01-05 77.980003 79.250000 76.860001 77.190002 26452200
2015-01-06 77.230003 77.589996 75.360001 76.150002 27399300
Any help would be greatly appreciated.

Related

cannot launch Jupyter from anaconda

I just got a new laptop at work and installed anaconda.. howerver, when i launched Jupyter I received the following error. Does anyone know what i should do here? Cheers
Traceback (most recent call last):
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 9, in
import sqlite3
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\lib\sqlite3\__init__.py", line 23, in
from sqlite3.dbapi2 import *
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\lib\sqlite3\dbapi2.py", line 27, in
from _sqlite3 import *
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\notebookapp.py", line 86, in
from .services.sessions.sessionmanager import SessionManager
File "C:\Users\darren.chapman\AppData\Local\Continuum\anaconda3\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 12, in
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
You have to add the path.
while installing click the add anoconda to the path.

library importing issues in pycharm

I'm doing a project on opencv python which is based on downloaded source code from the internet. When I run the code, this error occurs
C:\Users\Udara\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Udara/Desktop/7777/people-counting-opencv/people_counter.py
Traceback (most recent call last):
File "C:/Users/Udara/Desktop/7777/people-counting-opencv/people_counter.py", line 13, in <module>
from pyimagesearch.centroidtracker import CentroidTracker
File "C:\Users\Udara\Desktop\7777\people-counting-opencv\pyimagesearch\centroidtracker.py", line 5, in <module>
import ordereddict
File "C:\Users\Udara\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ordereddict.py", line 23, in <module>
from UserDict import DictMixin
ModuleNotFoundError: No module named 'UserDict'

failed to import sklearn in raspi3b ImportError: numpy.core.multiarray failed to import

i'm using python3 in my raspi. and i can't get sklearn to work or import pproperly in a code. i already tried to uninstall all numpy versions on my raspi. then only install numpy in python3 using: sudo apt-get install python3-numpy but i can't still get it to work. please help me everyone :(
thank you in advanced
this is the traceback of the error when importing sklearn
>>>
import sklearn
Traceback (most recent call last):
File "__init__.pxd", line 987, in numpy.import_array
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/sklearn/__init__.py", line 134, in <module>
from .base import clone
File "/usr/local/lib/python3.5/dist-packages/sklearn/base.py", line 13, in <module>
from .utils.fixes import signature
File "/usr/local/lib/python3.5/dist-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "sklearn/utils/murmurhash.pyx", line 26, in init sklearn.utils.murmurhash
File "__init__.pxd", line 989, in numpy.import_array
ImportError: numpy.core.multiarray failed to import

Cannot import name StringIO when importing dateutil

I'm having a 'Cannot import name StringIO' error message when importing dateutil which tries to import StringIO but cannot find it. Here is complete trace:
(DEV)arbi#el-oued:~/Work/sentimentpy$ python core/main.py
Traceback (most recent call last):
File "core/main.py", line 7, in <module>
from io.reader import *
File "/home/arbi/Work/sentimentpy/core/io/reader.py", line 4, in <module>
from dateutil import parser
File "/home/arbi/DEV/local/lib/python2.7/site-packages/dateutil/parser.py", line 22, in <module>
from io import StringIO
ImportError: cannot import name StringIO
When I tried to use python3 to launch my program, i had this error:
(DEV)arbi#el-oued:~/Work/sentimentpy$ python3 core/main.py
Traceback (most recent call last):
File "core/main.py", line 1, in <module>
from analyzer.length import LengthAnalyzer
File "/home/arbi/Work/sentimentpy/core/analyzer/length.py", line 4, in <module>
from numpy
ImportError: No module named numpy
Why I'm having this? i've installed numpy in my virtualenv with: pip install numpy
You are masking the built-in io module because you have a package named io in your project:
Traceback (most recent call last):
File "core/main.py", line 7, in <module>
from io.reader import *
File "/home/arbi/Work/sentimentpy/core/io/reader.py", line 4, in <module>
The line from io import StringIO finds /home/arbi/Work/sentimentpy/core/io, not the built-in module.
Rename that package or move it into a new top-level package name that doesn't conflict.
Your second error is unrelated; you simply don't have numpy installed for Python 3.

python-dbg can't find Py_InitModule4 when debugging

I'm trying to debug a segfault i get in a multithreaded, qt webkit application. I installed python-dbg for the purpose of giving me pretty printing in gdb and get the following error on start
python2.7-dbg node.py
Traceback (most recent call last):
File "node.py", line 4, in <module>
import msgpack
File "/usr/lib/pymodules/python2.7/msgpack/__init__.py", line 3, in <module>
from msgpack._msgpack import *
ImportError: /usr/lib/pymodules/python2.7/msgpack/_msgpack.so: undefined symbol: Py_InitModule4
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 20, in <module>
import apport.fileutils
File "/usr/lib/python2.7/dist-packages/apport/fileutils.py", line 22, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.7/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python2.7/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: /usr/lib/python2.7/dist-packages/apt_pkg.so: undefined symbol: Py_InitModule4
Original exception was:
Traceback (most recent call last):
File "node.py", line 4, in <module>
import msgpack
File "/usr/lib/pymodules/python2.7/msgpack/__init__.py", line 3, in <module>
from msgpack._msgpack import *
ImportError: /usr/lib/pymodules/python2.7/msgpack/_msgpack.so: undefined symbol: Py_InitModule4
I get the same thing when I run a version of the script that doesn't use msgpack...
Traceback (most recent call last):
File "scraper.py", line 2, in <module>
from planeswalker import PlaneswalkerParser
File "/var/www/rails_projects/MCPro.com/lib/planeswalker/planeswalker.py", line 2, in <module>
from PyQt4.QtCore import *
ImportError: /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so: undefined symbol: Py_InitModule4
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 1, in <module>
from apport.report import Report
File "/usr/lib/python2.7/dist-packages/apport/report.py", line 20, in <module>
import apport.fileutils
File "/usr/lib/python2.7/dist-packages/apport/fileutils.py", line 22, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python2.7/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python2.7/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: /usr/lib/python2.7/dist-packages/apt_pkg.so: undefined symbol: Py_InitModule4
Original exception was:
Traceback (most recent call last):
File "scraper.py", line 2, in <module>
from planeswalker import PlaneswalkerParser
File "/var/www/rails_projects/MCPro.com/lib/planeswalker/planeswalker.py", line 2, in <module>
from PyQt4.QtCore import *
ImportError: /usr/lib/python2.7/dist-packages/PyQt4/QtCore.so: undefined symbol: Py_InitModule4
in both cases its looking Py_InitModule4... any ideas python experts? Code runs fine (except for the segfault much later) with normal python 2.7
If there's an easier way to get pretty printing in gdb I'm open to that as well. Basically just looking for a python style stacktrace
after a bit of poking it looked like there were bugs related to this in past ubuntu python-dbg libraries. I filed a bug in suit and found out I just didn't read documentation. It is required to install the -dbg version of a library (MySQLdb and PyQT4 in this case)
There is no version for message pack so i'm posting another question on how to do that
here was the bug report marked invalid for reference https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/1040914

Categories

Resources