I'm trying to use python's iGraph module on my iMac running OSX 10.9.4. I've followed the steps on igraphs' front page for mac installation bur when I go to import igraph from the terminal, this is what I get.
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named igraph
Here are the steps that I've attempted to install igraph:
I intially had some problems with my pkg-config not being writable (I'm new to homebrew), so I followed these steps
brew install homebrew/science/igraph like posed here and linked the formula with brew link igraph and it brewed with no problems.
pip install python-igraph also finished cleanly.
From the igraphs documentation, this is all I need to do.
I looked into this answer but couldn't get the following line to work.
DYLD_LIBRARY_PATH=/usr/local/lib python -m igraph.test.__init__
/usr/bin/python: No module named igraph.test
This might suggest where the problem is but I don't know where to go from here.
Other information:
I have python installed through brew, but I'm not sure if that is causing the conflict. Regardless, Python2.7 should be the default python. I've installed other modules like numpy, scipy, and matplotlib with no problems.
Let me know if you need/want any other info.
Related
I've been having difficulty with Python recently, mainly since I think I had several versions and conflicts (due to Anaconda installs, canopy installs etc.). So I cleaned those out.
I reinstalled python (2.7) via brew.
I reinstalled numpy and matplotlib via pip.
I also reinstalled astropy and h5py via pip.
However, I get a clean import of numpy and matplotlib, but not of astropy and h5py:
~ > python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>> import astropy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named astropy
>>> import h5py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named h5py
>>>
My suspicion is that your pip executable is not linked to your python executable, which means when you run pip install astropy it is installing it in the site-packages for a different python.
One way to make sure you're using the correct pip is to not use
$ pip install astropy
but instead use
$ python -m pip install astropy
If this fails, it probably means that you don't have pip installed for the python instance you're using, and you need to install it (note that for Python 2 version 2.7.9 or later, or Python 3 version 3.4 or later, pip comes bundled with Python).
If this still doesn't work, then something stranger is going on. It may be due to having $PYTHONPATH or $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH set in a way that interferes with your python imports. In this case, you could clear these variables and try again. Otherwise, I'd consider using a package bundle such as conda or canopy. It makes these kinds of installation issues much smoother.
Edit: I see now that you've used conda and canopy, and you suspect these were causing your problems. Conda and canopy, by design, both sandbox their python installations so that they shouldn't get interference from other installs in your system, unless you force such interference by setting the environment variables I mentioned above. I'd suggest reinstalling conda and wiping those environment variables from your bash/csh startup script.
I have installed a python library MySQLdb, and it works yesterday. But today when I tried to run it, it goes on as following:
czhao#opx790:~$ python
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 2 2014, 12:34:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
It is really strange, so I try to re-install it, but it seems I do have the library in my computer:
czhao#opx790:~$ sudo apt-get install python-mysqldb
[sudo] password for czhao:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-mysqldb is already the newest version.
The following packages were automatically installed and are no longer required:
libgooglepinyin0-dev linux-headers-3.2.0-27 linux-headers-3.2.0-41
linux-headers-3.2.0-37 linux-headers-3.2.0-43 linux-headers-3.2.0-61
patchutils linux-headers-3.2.0-37-generic linux-headers-3.2.0-27-generic
linux-headers-3.2.0-61-generic linux-headers-3.2.0-43-generic dpatch
linux-headers-3.2.0-41-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
I do not know why, I have the library but python keep tell me I do not have it.
You are using Anaconda Python, but the package installed with apt-get was installed for the system Python. These two different distributions have different library directories, so packages/modules installed with one are not available for the other.
To get around this, use the pip program that came with Anaconda and run sudo pip install MySQL-python.
When a python module is installed successfully but fails to import in python (via PyCharm IDE), what could be the issue? What checklist should I follow to diagnose the problem in this case and in the future when a module installs but later fails to import?
For this specific case, I installed a vector graphics module for Python called cairo.
http://cairographics.org/releases/pycairo-1.8.8.tar.gz
See the successful install below:
sudo python setup.py install
cairo >= 1.8.8 detected
creating pycairo.pc
creating src/config.h
running install
running build
running build_ext
running install_lib
creating /Library/Python/2.7/site-packages/cairo
copying build/lib.macosx-10.9-intel-2.7/cairo/_cairo.so -> /Library/Python/2.7/site-packages/cairo
running install_data
creating /System/Library/Frameworks/Python.framework/Versions/2.7/include/pycairo
copying src/pycairo.h -> /System/Library/Frameworks/Python.framework/Versions/2.7/include/pycairo
copying pycairo.pc -> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/pkgconfig
running install_egg_info
Writing /Library/Python/2.7/site-packages/pycairo-1.8.8-py2.7.egg-info
Everything seemed to proceed smoothly, but later this module failed to import when called for in Python: ImportError: No module named cairo.
One possibility is that it was installed in the wrong directory - /Library/Python/2.7/site-packages/.
Another possibility is that I should be somehow telling python the location of the module explicitly. i.e.: /Library/Python/2.7/site-packages/cairo, based on the output of the install script found above.
It is quite odd, because cairo is present in /Library/Python/2.7/site-packages/, and I am able to import other libraries such as PIL found in the same directory.
Based on aIKID's suggestion, I tried using pip to get the installed packages. From this, I got a long list, including a module called pycairo. I tried importing both pycairo and cairo and still got an import error. It's interesting that "cairo" is found in /Library/Python/2.7/site-packages/cairo, but "pycairo" is found after a call of pip.get_installed_distributions(). It seems that the distribution is called pycairo, and the module is called cairo. import cairo should work, but either way both imports fail.
Based on Christopher's suggestion, I checked the /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ directory and did not find cairo. By the same token, I did not find PIL (the python imaging library). I am still able to import PIL, which is found in /Library/Python/2.7/site-packages/, together with cairo.
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL, cairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cairo
You can run python interactive mode and simply do the following steps to confirm your lib paths:
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path
<module 'posixpath' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc'>
As you can see, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ is the path in my system.
You might have multiple versions of python, but you can confirm which one you are using by doing this.
I am trying to use twisted on OS X Mavericks, but I get this error message when I try to import it.
christohersmbp2:~ christopherspears$ python
Python 2.7.6 (default, Mar 8 2014, 09:29:01)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twisted
My guess is that I am receiving this error because I am not using the default Python. I am using a Python installed with brew. Ideally, I would want to install twisted into a virtual environment to play with, but the docs are seriously lacking in details. Apparently, a dmg exists for Mac OS X 10.5, which is not helpful for me. I can install from the tarball into the virtual environment, but I am not sure how to do this. Any hints?
If you're using virtualenv, it doesn't matter whether you are using the system python or not.
Simply pip install twisted in your virtualenv, like:
$ workon MyTwistedEnv
$ pip install twisted
Currently, due to a bug in Xcode that affects all projects which contain extension modules, you may need to spell this
$ CFLAGS= pip install twisted
instead; hopefully this will be fixed soon. It may not affect brew installed Pythons, however.
I thought I'd move from using Tkinter to wxPython, but I'm having some troubles. All I get is this:
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
I have installed wxPython. When I run the uninstaller I clearly see that wxPython IS installed:
1. wxPython3.0-osx-cocoa-py2.7 3.0.0.0
Enter the number of the install to examine or 'Q' to quit:
When I start Python I see that my version should match the version of wxPython:
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I'm on OS X 10.7.5 32-bit.
Any help would be awesome! :)
Macs can have multiple versions of Python installed. Are you sure that you installed wxPython for the same python you invoke with the interpreter?
Try, which python, and make sure that this version of python has a wxredirect.pth file in site-packages pointing to the wxPython installation. (If it doesn't search for wxredirect.pth.)
Here's one version on my system...
> which python2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
> more /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wxredirect.pth
import site; site.addsitedir('/usr/local/lib/wxPython-3.0.0.0/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-2.9.1.1/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6')
Here, btw, I can comment out lines in the wxredirect.pth to choose the version of wxPython I want to use.
I just find the same problem.
I used brew install wxpython to install it on mac.
I try the method above but no use.
I happen to find the solution when I install another package, it showen below:
brew install tbb
Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.t
############################################################ 100.0%
==> Pouring tbb-2017_U7.sierra.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/ningrongye/.local/lib/python2.7/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-
packages")' >> /Users/ningrongye/.local/lib/python2.7/site-
packages/homebrew.pth`
this is what homebrew said and I just try those, and it works.
ningrong
I have Python 2.7 and 3.7 .
In /usr/local/bin/ there are symbolic links for 2.7 and 3.7 Python versions and also symbolic links for pip.
I've installed wxPython with pip3
pip3 install -U wxPython
Then i checked the installation for Python3
myname$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.4 osx-cocoa (phoenix) wxWidgets 3.0.5'
Antonio
In my case it worked by resetting the brew environment to 2.7:
brew link --overwrite python#2