gpt4 book ai didi

python - 在 python 2.7 中导入 Pandas 时出现 "ValueError: unknown locale: UTF-8"

转载 作者:IT老高 更新时间:2023-10-28 21:14:37 25 4
gpt4 key购买 nike

我是 python 的新手,想学习使用 pandas,但我什至无法在我的 python 中正确使用包。

在我尝试过的终端中

$ conda install pandas

结果是:

Fetching package metadata .......
Solving package specifications: ..........

# All requested packages already installed.
# packages in environment at /Users/rudyyuan/anaconda:
#
pandas 0.18.1 np111py27_0
Rudy-Yuans-MBP:~ rudyyuan$

然后我尝试使用 pip 安装:

Rudy-Yuans-MBP:~ rudyyuan$ pip install pandas
Requirement already satisfied (use --upgrade to upgrade): pandas in
./anaconda/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in
./anaconda/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in
./anaconda/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.7.0 in
./anaconda/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in
./anaconda/lib/python2.7/site-packages (from python-dateutil->pandas)

然后我进入

$ python

然后我进入

$ import pandas

输入命令的结果:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rudyyuan/anaconda/lib/python2.7/site-
packages/pandas/__init__.py", line 39, in <module>
from pandas.core.api import *
File "/Users/rudyyuan/anaconda/lib/python2.7/site- packages/pandas/core/api.py", line 10, in <module>
from pandas.core.groupby import Grouper
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 18, in <module>
from pandas.core.frame import DataFrame
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 39, in <module>
from pandas.core.series import Series
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/pandas/core/series.py", line 2944, in <module>
import pandas.tools.plotting as _gfx # noqa
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.py", line 27, in <module>
import pandas.tseries.converter as conv
File "/Users/rudyyuan/anaconda/lib/python2.7/site- packages/pandas/tseries/converter.py", line 7, in <module>
import matplotlib.units as units
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 1131, in <module>
rcParams = rc_params()
File "/Users/rudyyuan/anaconda/lib/python2.7/site-
packages/matplotlib/__init__.py", line 975, in rc_params
return rc_params_from_file(fname, fail_on_error)
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error)
File "/Users/rudyyuan/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/Users/rudyyuan/anaconda/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/Users/rudyyuan/anaconda/lib/python2.7/site- packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
encoding = locale.getdefaultlocale()[1]
File "/Users/rudyyuan/anaconda/lib/python2.7/locale.py", line 545, in getdefaultlocale
return _parse_localename(localename)
File "/Users/rudyyuan/anaconda/lib/python2.7/locale.py", line 477, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

但是当我尝试使用这个在本地检查包时:

import pip
sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])

里面已经显示了 Pandas ……:

['alabaster==0.7.8', 'anaconda-client==1.4.0', 'anaconda-navigator==1.2.1',    
'appnope==0.1.0', 'appscript==1.0.1', 'argcomplete==1.0.0', 'astropy==1.2.1',
'babel==2.3.3', 'backports-abc==0.4', 'backports.shutil-get-terminal-
size==1.0.0', 'backports.ssl-match-hostname==3.4.0.2',
'beautifulsoup4==4.4.1', 'bitarray==0.8.1', 'blaze==0.10.1', 'bokeh==0.12.0',
'boto==2.40.0', 'bottleneck==1.1.0', 'bz2file==0.98', 'cdecimal==2.3', '
cffi==1.6.0', 'chest==0.2.3', 'click==6.6', 'cloudpickle==0.2.1', 'clyent==1.2.2', 'colorama==0.3.7', 'conda-build==1.21.3', 'conda-env==2.5.0a0', 'conda==4.1.11', 'configobj==5.0.6', 'configparser==3.5.0b2', 'contextlib2==0.5.3', 'cryptography==1.4', 'cycler==0.10.0', 'cymem==1.31.2', 'cython==0.24', 'cytoolz==0.8.0', 'dask==0.10.0', 'datashape==0.5.2', 'decorator==4.0.10', 'dill==0.2.5', 'docutils==0.12', 'dynd==0.7.3.dev1', 'enum34==1.1.6', 'et-xmlfile==1.0.1', 'fastcache==1.0.2', 'flake8-docstrings==1.0.2', 'flake8==3.0.4', 'flask-cors==2.1.2', 'flask==0.11.1', 'funcsigs==1.0.2', 'functools32==3.2.3.post2', 'futures==3.0.5', 'gensim==0.12.4', 'gevent==1.1.1', 'greenlet==0.4.10', 'grin==1.2.1', 'h5py==2.6.0', 'heapdict==1.0.0', 'idna==2.1', 'imagesize==0.7.1', 'ipaddress==1.0.16', 'ipykernel==4.3.1', 'ipython-genutils==0.1.0', 'ipython==4.2.0', 'ipywidgets==4.1.1', 'itsdangerous==0.24', 'jdcal==1.2', 'jedi==0.9.0', 'jinja2==2.8', 'jsonschema==2.5.1', 'jupyter-client==4.3.0', 'jupyter-console==4.1.1', 'jupyter-core==4.1.0', 'jupyter==1.0.0', 'llvmlite==0.11.0', 'locket==0.2.0', 'lxml==3.6.0', 'markupsafe==0.23', 'matplotlib==1.5.1', 'mccabe==0.5.2', 'mistune==0.7.2', 'mpmath==0.19', 'multipledispatch==0.4.8', 'murmurhash==0.26.4', 'nb-anacondacloud==1.1.0', 'nb-conda-kernels==1.0.3', 'nb-conda==1.1.0', 'nbconvert==4.2.0', 'nbformat==4.0.1', 'nbpresent==3.0.2', 'networkx==1.11', 'nltk==3.2.1', 'nose==1.3.7', 'notebook==4.2.1', 'numba==0.26.0', 'numexpr==2.6.0', 'numpy==1.11.1', 'odo==0.5.0',
`enter code here`'openpyxl==2.3.2', 'pandas==0.18.1', 'partd==0.3.4', 'path.py==0.0.0', 'pathlib2==2.1.0', 'patsy==0.4.1', 'pep8==1.7.0', 'pexpect==4.0.1', 'pickleshare==0.7.2', 'pillow==3.2.0', 'pip==8.1.2', 'plac==0.9.6', 'ply==3.8', 'preshed==0.46.4', 'psutil==4.3.0', 'ptyprocess==0.5.1', 'py==1.4.31', 'pyasn1==0.1.9', 'pyaudio==0.2.7', 'pycodestyle==2.0.0', 'pycosat==0.6.1', 'pycparser==2.14', 'pycrypto==2.6.1', 'pycurl==7.43.0', 'pydocstyle==1.0.0', 'pyflakes==1.2.3', 'pygments==2.1.3', 'pyopenssl==16.0.0', 'pyparsing==2.1.4', 'pytest==2.9.2', 'python-',

什么问题以及如何解决这个问题?有什么和路径有关的吗?

我对 python 很陌生。

  1. 有什么问题?
  2. 我们该如何解决?

最佳答案

看起来您使用的是 OS X。将其附加到您的 ~/.bash_profile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

然后运行:

$ source ~/.bash_profile

现在试试 import pandas

关于python - 在 python 2.7 中导入 Pandas 时出现 "ValueError: unknown locale: UTF-8",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38916461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com