【问题标题】:python-Can't use modules installed by Homebrew?python-不能使用 Homebrew 安装的模块?
【发布时间】:2016-06-02 20:21:51
【问题描述】:

我想在我的python virtualenv 中使用essentia 模块,python 的版本是2.7.6。 在我执行之后

 brew tap MTG/essentia

我在我的 Pycharm 中找不到这个模块。

我也尝试过安装其他软件包,例如 matplotlib 使用

sudo pip install matplotlib

在我的 virtualenv 路径下。

The directory '/Users/username/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/username/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): matplotlib in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): tornado in /Library/Python/2.7/site-packages (from matplotlib)
Requirement already satisfied (use --upgrade to upgrade): pyparsing>=1.5.6 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib)
Collecting nose (from matplotlib)
/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading nose-1.3.7-py2-none-any.whl (154kB)
    100% |████████████████████████████████| 155kB 46kB/s
Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib)
Requirement already satisfied (use --upgrade to upgrade): six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from singledispatch->tornado->matplotlib)
Installing collected packages: nose
Successfully installed nose-1.3.7
You are using pip version 7.1.2, however version 8.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

我检查了 Pycharm,但是在解释器中没有 matplotlib 模块。 如何在我的 virtualenv 中安装软件包?

【问题讨论】:

  • 你是什么意思它不起作用?如果出现Permission denied 等错误,则应改用sudo pip install matplotlib。如果出现不同的错误,则需要不同的答案。

标签: python python-2.7 package virtualenv


【解决方案1】:

您不应使用brew 安装python 模块,而应使用pip。以下方法在 OSX 中对我有用。

Desktop     $ virtualenv myproject # Create the virtual environment
Desktop     $ cd myproject # Change into that directory
Desktop     $ source bin/activate # Enter the virtual environment
(myproject) $ sudo pip install matplotlib # Install matplotlib
(myproject) $ deactivate # Exit from the virtual environment

查看here 以获得对virtualenv 的进一步解释。

【讨论】:

  • source: no such file or directory: bin/activesource bin/active 之后?
  • 确保切换到项目目录。对我来说,我会在创建它之后做cd myproject。它应该可以在 Windows、OSX 和 Linux 上运行。
  • 很抱歉,我还没有真正解决问题。我正在尝试通过在全局环境下编译源代码来安装包,因为该库的文档没有提供 pip install 方法。
  • 正如@penguin-penpen 所说,并非所有软件包都可以使用 pip 安装。 Essentia 目前仅作为 python 的 brew 公式提供。
  • 我同意@Connor。如果包在 pip 上不可用,这将无济于事。
【解决方案2】:

如果pip包不可用,可以在本地python目录下找brew安装。

快速修复:

  • 将 essentia 安装到您的本地环境中。
  • 将本地 essentia 包附加到您的虚拟环境中

sys.path.append('/usr/local/lib/python2.7/site-packages') import essentia

长期修复:

  • 如果您想在虚拟环境中完全包含软件包,请尝试将本地 site-packages/essentia 文件夹复制到您的虚拟环境中
  • 复制任何其他依赖项,例如站点包/numpy。检查 brew 的 Cellar (/usr/local/Cellar) 是否有其他依赖项

【讨论】:

  • 嘿,我 brew 安装了一个包,我希望能够使用 python3 从安装 pip 的 jupyter notebook 导入它。我没有使用任何虚拟环境。我怎么解决这个问题?在“/usr/local/Cellar/open-babel”目录中,我有 bin、include、share 和 lib。我应该将哪些复制到“/usr/local/bin/python3/site-packages”?
猜你喜欢
  • 2012-06-18
  • 2012-04-03
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 2021-08-02
相关资源
最近更新 更多