Let me start by saying that I’m fairly new to Xcode, OS X, and installing python modules.
When I attempt to build my project, XCode tells me that it cannot find a python module:
File "/Users/some_user/some_folder/create.py", line 2, in <module>
from peak.rules import abstract, when
ImportError: No module named peak.rules
Command /bin/bash failed with exit code 1
I have installed a python module, which says it installed correctly. I can verify that it exists in my python2.7/site-packages/ directory. I also did which python, which gave me /Library/Frameworks/Python.framework/Versions/2.7/bin/python and verified that python is using that path python install for site packages, and it appears to be, they’re located at /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/. I’ve searched my machine and I don’t have another install of python that I’m aware of. I’ve restarted Xcode after installing the module and that did not make a difference. I also set PYTHONPATH to the site-packages directory specified by the same path given by which python.
My best guess as to the problem is that I’ve not defined my PYTHONPATH correctly. Here’s my entire .bash_profile file.
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
PYTHONPATH="$ {PYTHONPATH} : /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages"
export PYTHONPATH
The value of
PYTHONPATHdoes not indicate whichpythonexecutable to run. Rather, it is a way to augment in which directories apythonexecutable looks for modules during import operations. Apple ships versions of Python with OS X; the path to those interpreters are in/usr/bin. From the paths in your traceback (/Library/Frameworks), you appear to have installed a newer Python 2.7, possibly downloaded from python.org. By default, that python probably has symlinks to it installed in/usr/local/bin; its canonicalbindirectory is in the framework, at/Library/Frameworks/Python.framework/Versions/2.7/bin. While your shell path,$PATH, may have been set up to include that bin directory at the front of the search path so that the newer python is found in a shell, that probably doesn’t work for Xcode. In other words, Xcode is using the system Python, not the newer Python you installed. You’ll likely need to change some variables in your Xcode project so that the that path is searched first for that Python (or use an absolute path to the interpreter). You should remove thePYTHONPATHenvironment variable pointing at thesite-library. Each Python will, by default, automatically search itssite-library. More information is here.UPDATE: You may have a more basic issue here. I have no experience with
PEAKorPEAK-rulesbut note that there are two separate distributions listed in the Python Package Index. If you just want to use PEAK rules, it appears that you need to install just the PEAK-rules distribution and not the PEAK one listed in PyPI. To use with the system Python, try this:If you want to use the newer non-system Python, just install and use a copy of
easy_install(google forPyPI distribute) orpipfor it.