【问题标题】:Modifying .bashrc [duplicate]修改.bashrc [重复]
【发布时间】: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' 我应该将它添加到该文件中吗?

标签: python bash


【解决方案1】:

您似乎没有.bashrc。只需将.bashrc/etc/skel/ 复制到您的主目录。所以运行cp /etc/skel/.bashrc ~/.bashrc 应该可以解决您的问题。如果您没有目录/etc/skel/,那么只需执行touch ~/.bashrc 在您的主目录中创建一个名为.bashrc 的空文件。

现在您可以使用 echo 附加 EXPORT 行。即echo "export PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python" &gt;&gt; ~/.bashrc。 然后你可以使用source 命令重新加载它。


您的日志中的错误似乎与您的six 安装过程有关。尝试使用命令pip install --ignore-installed six重新安装它。

【讨论】:

  • 嘿@NaCl 我创建了 .bashrc 文件(并更新了我的问题),但仍然有问题。有什么想法吗?
  • @MorganAllen 我已经适当地编辑了我的答案。
  • 嘿@NaCl 我跑了pip install --upgrade google-api-python-client --ignore-installed six 并且成功了。当我去运行程序时,我看到了错误AttributeError: 'Module_six_moves_urllib_parse' object has no attribute 'urlparse'。当我按照他们的指示更新.bashrc 文件时,我感到很困惑......
  • 我添加了错误日志。看起来它仍然没有从正确的文件中读取它。
  • 我拍摄了我的目录的快照 - imgur.com/inQJAlz
猜你喜欢
  • 2015-08-30
  • 1970-01-01
  • 2012-05-29
  • 2014-03-24
  • 2012-10-07
  • 2015-08-02
  • 2013-05-03
  • 2011-10-27
  • 2013-07-30
相关资源
最近更新 更多