Python treq - 从一个目录运行,从另一个目录运行时出错

时间:2016-02-11 12:57:47

标签: python pycharm

我觉得我疯了。为什么会发生这种错误?

my_name@my_name-virtual-machine:/usr/local/lib/python2.7/dist-packages$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from treq.client import HTTPClient
>>> quit()
my_name@my_name-virtual-machine:/usr/local/lib/python2.7/dist-packages$ cd /home/my_name/dev/repo_name/code/
my_name@my_name-virtual-machine:~/dev/repo_name/code$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from treq.client import HTTPClient
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/treq/__init__.py", line 3, in <module>
    from treq.api import head, get, post, put, patch, delete, request
  File "/usr/local/lib/python2.7/dist-packages/treq/api.py", line 3, in <module>
    from treq.client import HTTPClient
  File "/usr/local/lib/python2.7/dist-packages/treq/client.py", line 34, in <module>
    from requests.cookies import cookiejar_from_dict, merge_cookies
ImportError: cannot import name merge_cookies

所以,当我在/usr/local/lib/python2.7/dist-packages时,我可以运行python shell并成功导入HTTPClient

我将目录更改为我的代码库,运行python shell并再次尝试相同的导入。它失败了。

为什么会这样?实际上,更好的问题是,我该如何调试呢?找出正在发生的事情的最佳方法是什么?

编辑1:

好的,所以我想我在某个时候删除了我的PYTHONPATH,因为我做了env | grep PYTHONPATH并且那里什么都没有。我在路径中添加了/usr/local/lib/python2.7/dist-packages,现在我可以从python控制台导入它。但是,我仍然无法从Pycharm运行它。

在Pycharm中我得到了同样的错误。有没有办法为Pycharm添加PAYTHON路径?

0 个答案:

没有答案