尝试在Python 2.7.6中使用pandas,它似乎无法加载pytz模块。以下是导致此错误的所有内容:
<?= _VARIABLE ?>
如您所见,Matts-MacBook-Pro-2:~ mattrosenthal$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Matts-MacBook-Pro-2:~ mattrosenthal$ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.version
2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
>>> print sys.path
#(added newlines for readability)
['',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython-0.20.1-py2.7-macosx-10.6-intel.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_dateutil-1.5-py2.7.egg',
'/Library/Python/2.7/site-packages/setuptools-3.5.1-py2.7.egg',
'/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg',
'/Library/Python/2.7/site-packages',
'/Library/Python/2.7/site-packages/pytz-2015.7-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
肯定存在于sys路径中。但是,当我尝试导入它时:
'/Library/Python/2.7/site-packages/pytz-2015.7-py2.7.egg'
我认为这是我试图解决的主要问题的根本原因,即由于没有加载pytz而导致大熊猫无法正确导入:
>>> import pytz
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytz
如果有帮助,请查看我当前的PATH变量:
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: No module named pytz.tzinfo 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.
我完全神秘,我将不胜感激!我尝试过使用pip,easy_install甚至手动将pytz .egg文件放在site-packages目录中,但这些文件看起来都不起作用。
修改:这是# 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
python -v -c "import pytz"