I have two pythons in my mac, they are python 3.4 and 2.7
I can import matplotlib in python 3.4 but as I run
from matplotlib import pyplot
I get the error:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from matplotlib import pyplot
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/backend_bases.py", line 62, in <module>
import matplotlib.textpath as textpath
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/textpath.py", line 18, in <module>
from matplotlib.mathtext import MathTextParser
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/mathtext.py", line 63, in <module>
import matplotlib._png as _png
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib-1.5.dev1-py3.4-macosx-10.6-intel.egg/matplotlib/_png.so
Reason: image not found
I am beginner. Can anybody help me figure out what is going on and what should I do?
This is your problem.
Library not loaded: libpng15.15.dylib
Use this sequence of commands to get to where you want.
pip uninstall matplotlib
rm -rf /tmp/pip-build-root/
brew update
brew install libpng --universal
brew install freetype --universal
pip install matplotlib
(venv) venv ~ python
Python 3.4.3 (default, Mar 23 2015, 04:19:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot
>>>
Simple solution to the issue that worked for me:
1- in terminal type $open -a Finder /usr
2- right click on local and do get info
3- unlock the lock at the bottom
4- click + sign and add your user to the list and give read/write privileges
5- click on the gear sign at the bottom and choose apply to enclosed items to recurse under that directory and assign privileges too all directories beneath it.
Related
When using python through the commandline, I am able to import modules fine. However, when I build a python script in SublimeText3, some modules don't import. I generally receive the following error:
ImportError: DLL load failed: The specified module could not be found.
The problem looks to involve modules with dependencies on modules with a "_" prefix (_sqlite3, _ssl). For example:
File "C:\ProgramData\anaconda3\Lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\ProgramData\anaconda3\Lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
System:
Windows 10
SublimeText3 (freshly reinstalled during troubleshooting)
Python 3.7.3 [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
(freshly reinstalled during troubleshooting)
Both commandline and ST3 or pointing to same instance of Python.
This is the only python install on the machine.
Have used default Python build in ST3 and created a new build, both have same issue.
Results when using the commandline:
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import plotly
>>>
Results in ST3:
import plotly
Traceback (most recent call last):
File "C:\Users\usr\Desktop\scrap.py", line 1, in <module>
import plotly
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\__init__.py", line 32, in <module>
from plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\graph_objs\__init__.py", line 3, in <module>
from plotly.basedatatypes import BaseLayoutType as _BaseLayoutType
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\basedatatypes.py", line 25, in <module>
from .callbacks import (Points, InputDeviceState)
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\callbacks.py", line 2, in <module>
from plotly.utils import _list_repr_elided
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\utils.py", line 262, in <module>
from chart_studio.utils import *
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\__init__.py", line 2, in <module>
from chart_studio import (plotly, dashboard_objs, grid_objs, session)
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\__init__.py", line 10, in <module>
from . plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\plotly.py", line 38, in <module>
from chart_studio.plotly import chunked_requests
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\__init__.py", line 1, in <module>
from . chunked_request import Stream
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\chunked_request.py", line 4, in <module>
import ssl
File "C:\ProgramData\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.
[Finished in 2.9s]
Any help much appreciated, been stuck on this for days.
For those with a similar issue in the future, I've fixed this by uninstalling the Anaconda distribution of Python and replacing it with a base Python installation from Python.org, then installing packages using pip manually. While not the ideal solution, this has solved the issue so that when I build a Python script in ST3, all modules are imported fine.
I usually work with python 2.7 but this time i have to test a script in python3.
It is already installed on my computer, however when i start "python3", then go "import numpy", it show me "cannot import name 'multiarray'.
I even installed anaconda3 to test, but nothing happens
myName:~/anaconda3/bin$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I saw that it is looking in the lib/python2.7, but i cannot find what to do to get him search in the python3 library.
I already tried python -m pip install numpy, and tried to create a virtualenv in python3 but i still get the same error.
I cannot figure what to do. Can someone help me ?
I would like to add, i cannot start command with 'sudo' as i'm working on a client machine.
edit:
i tried #gehbiszumeis answer and got this:
myName:~ $ cd anaconda3/bin/
myName:~/anaconda3/bin $ source activate /home/myName/anaconda3
(base) myName:~/anaconda3/bin $ conda list numpy
# packages in environment at /home/myName/anaconda3:
#
# Name Version Build Channel
numpy 1.14.3 py36hcd700cb_1
numpy-base 1.14.3 py36h9be14a7_1
numpydoc 0.8.0 py36_0
(base) myName:~/anaconda3/bin $ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I see there is numpy 36 installed when i type conda list numpy, but it seems not to work.. Did i miss something ?
edit2:
After #Pal Szabo method, i tested command python3 -m pip install --upgrade pip and got this error :
(env) (base) myName:~/anaconda3/bin $ python3 -m pip install --upgrade pip
Traceback (most recent call last):
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 4, in <module>
import locale
File "/home/myName/anaconda3/bin/env/lib/python3.6/locale.py", line 16, in <module>
import re
File "/home/myName/anaconda3/bin/env/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'`
It is a crazy mix between python3, python2.7 then again python3. I'm lost \o/
edit3:
I finally found my error.
It was a probleme with my PYTHONPATH, which was pointing somewhere where a .pth file was defined, with some hard link to python 2.7 libraries.
with a simple "unset PYTHONPATH" it works fine.
Thanks you all
I had the same problem, took me several hours to figure it out.
In my case, the PYTHONPATH was set to /usr/lib/python2.6/dist-packages/
changing it to /Users/xxx/miniconda3/lib/python3.7/site-packages/ resolved the issue.
Good luck.
Based what I can see from your code listing, it seems that the anaconda environment is not activated (this is usually indicated by the environments name in surrounding brackets () before the prompt). Because of that python3 tries to look for numpy and only finds the one you used for python 2.7 previously, which causes the error (see the python2.7 error messages)
Try
source activate <your-anaconda-environment>
Then your prompt should look like this
(<your-anaconda-environment>) myName:~/anaconda3/bin$
Numpy should be contained in the standard anaconda environment. Try then to check if numpy is installed within your environment with
conda list numpy
If there is no numpy listed, try to install it with pip as you wrote before.
If want to use python3, use pip3 instead of pip:
pip3 install numpy
You can try these too in terminal:
rm -Rf env
virtualenv -p python3 env
source env/bin/activate
python3 -m pip install --upgrade pip
pip3 install numpy
Also make sure that the first line of your script is
#!/usr/bin/python3
Don't write anything, even comments, before this.
I solved this problem changing the Python's version on VS Code. I was working with Python 3.7.4, now with the 3.7.8 one.
When I installed Numpy, it was stored in the folder of Python3.6. So I think that u could try to change the path or just change the Python's version
I successfully installed Anaconda, Python2.7, and matplotlib on my Mac OS laptop.
However, when I import matplotlib.pyplot, I get the following errors:
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 5 2017, 02:28:52)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user.name/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 32, in <module>
import matplotlib.colorbar
File "/Users/user.name/anaconda2/lib/python2.7/site-packages/matplotlib/colorbar.py", line 36, in <module>
import matplotlib.contour as contour
File "/Users/user.name/anaconda2/lib/python2.7/site-packages/matplotlib/contour.py", line 21, in <module>
import matplotlib.font_manager as font_manager
File "/Users/user.name/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py", line 58, in <module>
from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
ImportError: dlopen(/Users/user.name/anaconda2/lib/python2.7/site-packages/matplotlib/ft2font.so, 2): Symbol not found: _inflateValidate
Referenced from: /Users/user.name/anaconda2/lib/libpng16.16.dylib
Expected in: /usr/lib/libz.1.dylib
in /Users/user.name/anaconda2/lib/libpng16.16.dylib
>>>
Here are the Conda versions of the libraries mentioned above in the error messages:
conda list matplotlib
# packages in environment at /Users/user.name/anaconda2:
#
# Name Version Build Channel
matplotlib 2.1.2 py27h6d6146d_0
conda list libpng
# packages in environment at /Users/user.name/anaconda2:
#
# Name Version Build Channel
libpng 1.6.34 he12f830_0
conda list zlib
# packages in environment at /Users/user.name/anaconda2:
#
# Name Version Build Channel
zlib 1.2.11 hf3cbc9b_2
Does anyone know how to fix this problem?
Possible cause: the first time you use/import matplotlib, it (tries to) builds a fontcache directory. This is both slow and error-prone.
See: matplotlib taking time when being imported
If it fails or uses wrong permissions, delete the files/directories involved and restart.
I figured it out myself. Anaconda needed libz, which I had already installed with conda and was placed into the default location /Users/user.name/anaconda2/lib on my Mac. However, Python was seeing the libz that came with my Mac in /usr/lib/.
I fixed the problem by unsetting the environment variable LD_LIBRARY_PATH on my system. That apparently allowed Anaconda to find the correct libz.
I have tried adding new libraries to my python installation such as numpy and matplotlib. However, after their installation I keep getting the error message.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Issiah>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module
>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module
>
from .type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <mod
ule>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 24, in <modu
le>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
>>> exit()
C:\Users\Issiah>python -m pip install numpy
Requirement already satisfied: numpy in c:\python27\lib\site-packages
C:\Users\Issiah>python -m pip install numpy --force-reinstall
Requirement already satisfied: numpy in c:\python27\lib\site-packages
C:\Users\Issiah>
Here's another error from importing Pygame.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pygame\__init__.py", line 95,
from pygame.base import *
ImportError: DLL load failed: %1 is not a valid Win32 application.
It first started happening when I installed them using their respective setup.exe programs. Sometime later I used "pip install" and they all installed and imported without errors(I didn't actually use any of their library functions though). I then comeback the next day and upon import I started to get this error message.
Thanks for any advice.
I am trying to run the following script in my virtualenv:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ couchy.py
Traceback (most recent call last):
File "/home/gonvaled/projects/bin/couchy.py", line 46, in <module>
from couchdb_support import CouchdbLists
File "/home/gonvaled/projects/test_project/python_modules/couchdb_support.py", line 3615, in <module>
from asterisk_support import AsteriskSupport
File "/home/gonvaled/projects/test_project/python_modules/asterisk_support.py", line 4, in <module>
from starpy_support import AmiCommand
File "/home/gonvaled/projects/test_project/python_modules/starpy_support.py", line 7, in <module>
from starpy import manager, fastagi, utilapplication, menu
File "/usr/lib/python2.5/site-packages/starpy/utilapplication.py", line 2, in <module>
from basicproperty import common, propertied, basic, weak
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basicproperty/common.py", line 159, in <module>
from basictypes import datedatetime_types as ddt
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basictypes/datedatetime_types.py", line 4, in <module>
from dateutil import parser
File "/usr/lib/python2.5/site-packages/python_dateutil-2.1-py2.5.egg/dateutil/parser.py", line 8
from __future__ import unicode_literals
SyntaxError: future feature unicode_literals is not defined
So somehow python is trying to import from:
/usr/lib/python2.5/site-packages/starpy/utilapplication.py
This does not make any sense. My virtualenv is very clean:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ python
Python 2.7.2 (default, Mar 29 2012, 00:31:29)
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/Twisted-12.0.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/zope.interface-3.8.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/basicproperty-0.6.12a-py2.7-linux-i686.egg', '/home/gonvaled/projects/gonvaled_settings', '/home/gonvaled/django_apps', '/home/gonvaled/projects/test_project/ipc', '/home/gonvaled/projects/test_project/python_modules', '/home/gonvaled/projects/test_project/gdata', '/home/gonvaled/projects/callisto/libraries', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python27.zip', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/plat-linux2', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-old', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-dynload', '/usr/local/python/2.7.2/lib/python2.7', '/usr/local/python/2.7.2/lib/python2.7/plat-linux2', '/usr/local/python/2.7.2/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages']
And:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ pip freeze
CouchDB==0.9dev
DateUtils==0.5.1
Twisted==12.0.0
basicproperty==0.6.12a
pystache==0.4.0
python-dateutil==2.1
pytz==2012b
simplejson==2.4.0
six==1.1.0
starpy==1.0.0a12
wsgiref==0.1.2
zope.interface==3.8.0
So to summarize: python is importing from /usr/lib/python2.5/site-packages even though I am inside a virtualenv. How can this be?
Try running the script as:
$ python couch.py
in your activated virtualenv. Depending on your system and the first line (the shebang line) of the file, you may not be running in the Python you think you are.
You should create your virtualenv with the --nositepackages option to keep it clean and away from your system Python.