python - Pip Install 没有安装到正确的目录?

标签 python bash installation pip

我似乎无法正确使用 sudo pip install 以便它安装到以下目录:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

这样我就可以使用 python 导入模块了

我跑了

sudo pip install scikit-learn --upgrade

结果

Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/site-packages
Cleaning up...

但是,它不在正确的目录中

如何让 sudo pip install 安装到正确的目录?

另外,我试过了

sudo pip install Scrappy

我收到以下消息

new-host-2:site-packages Chris$ sudo pip install Scrapy
Password:
Requirement already satisfied (use --upgrade to upgrade): Scrapy in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.8.0 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/site-packages (from Twisted>=10.0.0->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cryptography>=0.2.1 in /usr/local/lib/python2.7/site-packages (from pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/site-packages (from zope.interface>=3.6.0->Twisted>=10.0.0->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cffi>=0.8 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.2.1->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=0.8->cryptography>=0.2.1->pyOpenSSL->Scrapy)

这两个实例都表明它已安装但不正确。例如,当我在 python 中运行以下导入时:

import scrapy
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-51c73a18167b> in <module>()
----> 1 import scrapy

ImportError: No module named scrapy

我尝试了以下方法:

sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

最佳答案

从对原始问题的评论来看,您似乎安装了多个版本的 python,而 pip 只是转到了错误的版本。

首先,要知道您使用的是哪个版本的 python,只需输入 which python。您应该看到:

which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

如果你要使用正确版本的 python,或者:

which python
/usr/bin/python

如果您要使用“错误”版本。要使 pip 转到正确的版本,您首先必须更改路径:

 export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin/python:${PATH}

现在输入“which python”会让你得到正确的结果。接下来,安装 pip(如果尚未为此安装 python 安装它)。最后,使用它。你现在应该没事了。

关于python - Pip Install 没有安装到正确的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25607837/

相关文章:

python - Python 中的 MemoryError 钩子(Hook)?

python - 如何调试我使用 ctypes 从 Python 调用的 Visual Studio 中的 DLL?

linux - tar exclude 在 bash 脚本中不起作用

linux - bash - 根据过程条件返回值

rubygems - 无法在Windows中通过Ruby安装任何gem

xcode - 使用 applescript 安装 ffmpeg

python - 如何从 s3 下载图像作为 numpy 数组?

python - 打印一个 Jupyter 单元格中定义的所有变量

python - 是否可以执行 bash 脚本来下载 `pip install my-package` 上的非 python 依赖项

PHP安装配置: error: Cannot find php_pdo_driver. h