简体   繁体   English

pip和python的路径不同步?

[英]Paths for pip and python out of sync?

I have an application that is using the requests module. 我有一个使用请求模块的应用程序。 I have installed this module but when I try to run my app it throws the error: 我已经安装了此模块,但是当我尝试运行我的应用程序时,它将引发错误:

    import requests
ImportError: No module named requests

When I run pip list i see an entry for requests: 当我运行pip list我看到一个请求条目:

...
pytz (2017.2)
requests (2.18.4)
scipy (0.19.1)
...

so I know it's installed. 所以我知道它已经安装了

I confirmed that both pip and python are version 2.7: 我确认pip和python均为2.7版:

➜  pip --version
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
➜  python --version
Python 2.7.10

When I look at the paths for pip and python they look to be different: 当我查看pip和python的路径时,它们看起来是不同的:

➜  which pip
/usr/local/bin/pip
➜  which python
/usr/bin/python

Am I correct in suspecting that these mismatched paths are the cause of my problem? 我怀疑这些不匹配的路径是我的问题的原因吗?

What would cause this to happen? 什么会导致这种情况发生? I had assumed that as long as both pip/python were 2.7 they would be working together well. 我假设只要pip / python均为2.7,它们就可以很好地协同工作。

How can I fix this problem? 我该如何解决这个问题?

This seems like something that would have already been solved, but after googling and going over the suggested questions when creating this post I haven't come across a post that has a clear solution that goes over both how this could happen and how to fix it. 这看起来似乎已经解决了,但是在创建此帖子时谷歌搜索并仔细研究了所建议的问题之后,我还没有遇到过具有明确解决方案的文章,该解决方案既不涉及这种情况的发生方式,也涉及解决方法。

I would suggest trying some of these options: 我建议尝试以下选项:

1) Make sure that you have an environment variable pointing to where the current pip directory is. 1)确保您有一个环境变量指向当前pip目录所在的位置。 2) Move the pip folder to the directory that your other python packages are in. 3) Uninstall and then reinstall pip (to a different location on your path). 2)将pip文件夹移至其他python软件包所在的目录。3)卸载pip,然后重新安装(到路径上的其他位置)。 4) Uninstall python and then reinstall python. 4)卸载python,然后重新安装python。 I would suggest installing it through conda or miniconda to make sure that you have everything downloaded to the same place. 我建议通过conda或miniconda安装它,以确保将所有内容下载到同一位置。 Miniconda will by default store pip with all of the other packages and should run cleanly. Miniconda默认情况下会将pip与所有其他软件包一起存储,并且应该运行干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM