python – 使OSX中的matplotlib在虚拟环境中工作的最简单的方法是什么?

我刚刚发现matplotlib在虚拟环境中有问题.我在FAQs尝试过解决方案,但是没有工作.一个理想的解决方案应该只涉及到pip命令,但是请求它可能很难或不切实际.无论如何,我尝试了他们在OS X部分,在您的venv文件夹中创建一个框架bash文件,并通过它运行命令.

$frameworkpython krls.py

当我这样做时,我得到一个权限deniel错误:

Permission denied

我很害怕sudoing命令,我不是100%他们做什么…反正,似乎bash脚本没有做任何事情太危险,所以我继续下去.但是,我的终端的响应是奇怪的,它说:

sudo frameworkpython krsl.py
sudo: frameworkpython: command not found

这意味着它不会将frameworkpython识别为命令.没有sudo它说:

frameworkpython krsl.py
-bash:/ Users / my_name / path / venv / bin / frameworkpython:权限被拒绝

这似乎将frameworkpython识别为命令(?),但由于权限,它没有执行它?对我来说似乎很奇怪任何人有什么想法?

我也试过:

$pip install TKAgg
Collecting TKAgg
  Could not find a version that satisfies the requirement TKAgg (from versions: )
No matching distribution found for TKAgg

但它没有奏效.

所以我尝试了使用PySide的下一个选项,它也没有工作,并给出了一个巨大的错误输出:

$pip install pyside
Collecting pyside
  Using cached PySide-1.2.4.tar.gz
Building wheels for collected packages: pyside
  Running setup.py bdist_wheel for pyside ... error
  Complete output from command /Users/my_name/path/venv/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/tmpUR9qFCpip-wheel- --python-tag cp27:
  Removing /private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/pyside_package
  running bdist_wheel
  running build
  Python architecture is 64bit
  error: Failed to find cmake. Please specify the path to cmake with --cmake parameter.

  ----------------------------------------
  Failed building wheel for pyside
  Running setup.py clean for pyside
Failed to build pyside
Installing collected packages: pyside
  Running setup.py install for pyside ... error
    Complete output from command /Users/my_name/path/venv/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-UVA_F4-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/my_name/path/venv/bin/../include/site/python2.7/pyside:
    Removing /private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/pyside_package
    running install
    running build
    Python architecture is 64bit
    error: Failed to find cmake. Please specify the path to cmake with --cmake parameter.

    ----------------------------------------
Command "/Users/my_name/path/venv/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-UVA_F4-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/my_name/path/venv/bin/../include/site/python2.7/pyside" failed with error code 1 in /private/var/folders/nr/rxlk6w192hx8r74813yg6r500000gn/T/pip-build-_yzDki/pyside/

之后,我尝试使用WX Phonix的下一个选项.不幸的是,我经历了他们的网站,找不到如何做到这一点.

FAQS you reference所述,您将需要在venv / bin中创建一个frameworkpython脚本.看起来你的系统无法找到frameworkpython,所以它不是在你的系统$PATH或它不可执行.

确保您通过chmod x venv / bin / frameworkpython使这个脚本可执行!

Linux/Unix docs(我加粗体):

PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files.

您的系统将仅查找可通过PATH环境变量访问的可执行文件,从而跳过不可执行文件.

创建frameworkpython脚本是必要的,因为matplotlib需要python的框架构建.从以上链接:

Unfortunately virtualenv creates a non framework build even if created from a framework build of Python.

这是另一个post,有更多关于框架构建的细节

更新:

使用Python3,您可以通过-m venv使用virtualenv的内置实现:

python -m venv <name of virtualenv>
source <name of virtualenv>/bin/activate

Python3的内置实现构建了virtualenv,使得Python被设置为一个框架,所以不需要配置任何东西来使其工作.更多细节here.

http://stackoverflow.com/questions/38090455/what-is-the-simplest-way-to-make-matplotlib-in-osx-work-in-a-virtual-environment

转载注明原文:python – 使OSX中的matplotlib在虚拟环境中工作的最简单的方法是什么?