【发布时间】:2016-04-21 14:06:17
【问题描述】:
我对使用 VIM 或 bash 不是很熟悉,但我正在尝试让 google gmail API 工作。
https://developers.google.com/gmail/api/quickstart/python#step_4_run_the_sample
底部有说明
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
此错误可能发生在 Mac OSX 中,其中“六”模块的默认安装(此库的依赖项)在 pip 安装之前加载。要解决此问题,请将 pip 的安装位置添加到 PYTHONPATH 系统环境变量中:
使用以下命令确定 pip 的安装位置:
pip show six | grep "Location:" | cut -d " " -f2
当我运行它时,我得到/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
在你的 ~/.bashrc 文件中添加以下行,替换为上面确定的值:
export PYTHONPATH=$PYTHONPATH:<pip_install_path>
我的.bashrc 文件中有 1 行:
export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
(export 或其余部分之间没有中断,所以当我将其粘贴时正在创建中断)
使用以下命令在任何打开的终端窗口中重新加载您的 ~/.bashrc 文件:
source ~/.bashrc
但是,当我输入 cd ~ 和 ls -a 时,我只看到 .bashrc .bash_sessions
如何打开和修改.bashrc?
这是错误文件
Installing collected packages: six, httplib2, pyasn1, pyasn1-modules, rsa, oauth2client, simplejson, uritemplate, google-api-python-client
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 726, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 746, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/0p/503b1d894jz0z8rfyhw6jmzh0000gn/T/pip-xPddj0-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
当我运行quickstart.py 文件时:
Morgans-iMac:iMac morganallen$ python quickstar.py
Traceback (most recent call last):
File "quickstar.py", line 73, in <module>
main()
File "quickstar.py", line 57, in main
credentials = get_credentials()
File "quickstar.py", line 45, in get_credentials
credentials = tools.run_flow(flow, store, flags)
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/tools.py", line 199, in run_flow
authorize_url = flow.step1_get_authorize_url()
File "/Library/Python/2.7/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 1991, in step1_get_authorize_url
return _update_query_params(self.auth_uri, query_params)
File "/Library/Python/2.7/site-packages/oauth2client/client.py", line 491, in _update_query_params
parts = urllib.parse.urlparse(uri)
AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'
【问题讨论】:
-
如果您没有 .bashrc 文件,您可以随时添加。键入
vim .bashrc,vim 将打开一个名为.bashrc 的新文件。然后按照说明将信息输入到文件中。 -
另外值得指出的是,OS X 在默认情况下实际上可能不会读取
.bashrc,您可能需要为此使用.bash_profile(或从.bash_profile读取.bashrc)。 -
我也没有
.bash_profile文件...只是 `.bash_sessions' 我应该将它添加到该文件中吗?