Issue with Anaconda Python 3.5 script - python

Having an issue with a fresh install of Anaconda. I created an environment with Python 3.5 and trying to run a simple script but for whatever reason I am seeing an issue during the import statements.
import os
import csv
import numpy as np
import scipy
So there are other reports of similar errors on SO but they are from awhile back and do not seem to be linked to Anaconda. I have NOT seen this before on my laptop )running el capitan) also running miniconda (btw this is happening on a mac osx el capitan). I cannot understand why anaconda would try calling usr/local/lib/python2.7 while the environment is in python 3.5. Is this normal? Any assistance would be greatly appreciated!!!
Traceback (most recent call last):
File "myTest.py", line 11, in <module>
import scipy
File "/Users/dennis/anaconda/envs/test/lib/python3.5/site-packages/scipy/__init__.py", line 61, in <module>
from numpy import show_config as show_numpy_config
File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so
Expected in: flat namespace
in /usr/local/lib/python2.7/site-packages/numpy/core/multiarray.so

Well after digging around and trying to solve this issue most of last night I could not come up with much. I must have done something to my environment (I had done some builds of a couple of libraries from source)...anyway worst StackOverflow answer of all time, I used my TimeMachine to reset my mac back a week and the issue is gone. I guess the lesson is even if you are using environments in anaconda backups still cannot be beat.

Related

ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant'

Traceback (most recent call last):
File "g:\mydrive\ \pdftotext_pdfminer.py", line 3, in <module>
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\pdfinterp.py", line 7, in <module>
from .cmapdb import CMap
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\encodingdb.py", line 7, in <module>
from .psparser import PSLiteral
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\psparser.py", line 22, in <module>
from .utils import choplist
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\pdfminer\utils.py", line 31, in <module>
import charset_normalizer # For str encoding detection
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\__init__.py", line 23, in <module>
from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
File "C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\api.py", line 10, in <module>
from charset_normalizer.md import mess_ratio
File "charset_normalizer\md.py", line 5, in <module>
ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (C:\Users\ \anaconda3\envs\ \lib\site-packages\charset_normalizer\constant.py)
This error happens whenever I'm using pdfminer. I also installed pdfminer-six
My code worked just fine until two days ago.
It started to happen today when I tried to just run it again without any adjustment in the file
I'm assuming maybe it's the pdfminer's problem but there's no update about the module...
(I'm running this on my conda env)
Does anyone know what this error means? and how to fix it?
When I encountered this I used:
pip install chardet
there. I faced the same problem when trying to use the pdfplumber package today (2022-11-24) from a script I have long used with no problem. I don't know why this error is happening but found one of the solutions in this link helpful:
How to fix AttributeError: partially initialized module?
Briefly, I removed my entire virtual environment using the command conda env remove --name ds (being ds the name of my environment). Then, I created a new one and installed every package I needed again through conda or pip. It is working perfectly now. Hope it works for you as well.
Out of curiosity, I have installed Tensorflow last week. Maybe it interfered with pdfplumber somehow (not sure). Have you installed any new package since the last time you used pdfminer? Best of luck!
use follow instead.
pip install mmcv-full==1.3.17

'import discord' not working in Python 3.5

I try to import discord in python 3.5, but I get the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python35-32\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "C:\Python\Python35-32\lib\site- packages\discord\client.py", line 42, in <module>
from .voice_client import VoiceClient
File "C:\Python\Python35-32\lib\site- packages\discord\voice_client.py", line 65, in <module>
from .gateway import *
File "C:\Python\Python35-32\lib\site- packages\discord\gateway.py", line 31, in <module>
import aiohttp
File "C:\Python\Python35-32\lib\site- packages\aiohttp\__init__.py", line 10, in <module>
from .protocol import * # noqa
File "C:\Python\Python35-32\lib\site- packages\aiohttp\protocol.py", line 11, in <module>
from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'
I installed discord inside Python35-32\Scripts using pip install discord. Additionally, I installed asyncio using pip install asyncio in the same directory.
The error pops up in my command prompt, when I type in "python", wait for it to open, and then type "import discord". I'm saying that just to be clear that it's not a "I have a file named XXX.py which clashes with something from the discord library" type of error.
Based on the comments you have added and the line
File "C:\Python\Python35-32\lib\site- packages\aiohttp\protocol.py", line 11, in <module>
from wsgiref.handlers import format_date_time
ImportError: cannot import name 'format_date_time'
The problem seems to be that 'format_date_time' could not be imported from the built in library wsgiref. Turns out that the file ...\Python35-32\lib\wsgiref\handlers.py was completely empty indicating that something corrupted your python installation.
Two possible solutions:
Reinstall your python completely which also has the benefit of solving other potential corruptions that you might not have noticed yet (Note that the underlying cause for this corruption remains unknown)
Go into the Cython git and copy the contents of the handlers.py into the local file. This is a very specific solution however and you should be aware that other parts of your python installation might also be corrupt.
Maybe you wanted to pip install discord.py instead of discord?

Importing SparkContext from pyspark running Jupyter Notebook on AWS EC2 [duplicate]

import numpy as np
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 57, in <module>
from numpy.testing import Tester
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 14, in <module>
from .utils import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp
File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/home/anirrudh/OMSCS/Courses/ML4T/ml4t/mc3_p2/random.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
import numpy.ma as ma
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/__init__.py", line 44, in <module>
from . import core
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/core.py", line 30, in <module>
import numpy.core.umath as umath
AttributeError: 'module' object has no attribute 'core'
I am working on Ubuntu 14.04. I tried reinstalling numpy, created a new virtualenv, but it isn't helping. I get the same error outside the virtualenv as well. It stopped working suddenly. It was fine until a little while ago.
(Answer posted on behalf of the OP).
Update: Resolved.
I had created a python file for one of my projects name random.py and when numpy is imported, it was calling this file instead of it's own library file hence resulting in the error. I had to delete/rename random.py which I created and that fixed the issue.
Try running it in Python 2 instead of Python 3 - you may have the older version of Spark
This happened to me in Windows with Anaconda. I fixed it by removing the python3 path from the environment variable PATH.
Another common problem here (which I had)...check to make sure you dont have a PYTHONPATH env var pointing to a different version of python site-packages (this happened because I updated my python version and didn't change this...it loads from PYTHONPATH first).
It happened to me in a specific ipynb, once I crated a copy of the notebook with a different name I was able to import numpy.

Numpy import throws AttributeError: 'module' object has no attribute 'core'

import numpy as np
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 57, in <module>
from numpy.testing import Tester
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 14, in <module>
from .utils import *
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp
File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/home/anirrudh/OMSCS/Courses/ML4T/ml4t/mc3_p2/random.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
import numpy.ma as ma
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/__init__.py", line 44, in <module>
from . import core
File "/home/anirrudh/.virtualenvs/ml4t2/local/lib/python2.7/site-packages/numpy/ma/core.py", line 30, in <module>
import numpy.core.umath as umath
AttributeError: 'module' object has no attribute 'core'
I am working on Ubuntu 14.04. I tried reinstalling numpy, created a new virtualenv, but it isn't helping. I get the same error outside the virtualenv as well. It stopped working suddenly. It was fine until a little while ago.
(Answer posted on behalf of the OP).
Update: Resolved.
I had created a python file for one of my projects name random.py and when numpy is imported, it was calling this file instead of it's own library file hence resulting in the error. I had to delete/rename random.py which I created and that fixed the issue.
Try running it in Python 2 instead of Python 3 - you may have the older version of Spark
This happened to me in Windows with Anaconda. I fixed it by removing the python3 path from the environment variable PATH.
Another common problem here (which I had)...check to make sure you dont have a PYTHONPATH env var pointing to a different version of python site-packages (this happened because I updated my python version and didn't change this...it loads from PYTHONPATH first).
It happened to me in a specific ipynb, once I crated a copy of the notebook with a different name I was able to import numpy.

CRegExp error in Ipython

I love ipython, I am learning python now as a replacement of R for data analysis. However at promt I get the following message:
$ ipython --qtconsole
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/Current/bin/ipython", line 5, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/__init__.py", line 46, in <module>
from .frontend.terminal.embed import embed
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/embed.py", line 39, in <module>
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 33, in <module>
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 44, in <module>
from IPython.core import prefilter
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/prefilter.py", line 48, in <module>
from IPython.utils.traitlets import (
ImportError: cannot import name CRegExp
Ipython worked just fine a week ago and now I get this error. Can anybody suggest what might be causing this?
As #favoretti mentioned, this is an import issue in utils.traitlets.
I would recommend upgrading to EPD 7.3 and see if that fixes the issue. I feel bad suggesting a "brush it under the carpet" solution but if you're just starting out with python delving into the bowels of IPython might be a bit of a headache.

Categories