使OSX中的matplotlib在虚拟环境中工作的最简单方法是什么? [英] What is the simplest way to make matplotlib in OSX work in a virtual environment?

查看:101
本文介绍了使OSX中的matplotlib在虚拟环境中工作的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现matplotlib与虚拟环境有关.我在常见问题解答中尝试了这些解决方案,但是它们没有用.理想的解决方案应该只包含pip命令,但是请求它可能很困难或不切实际.无论如何,我尝试了他们在OS X部分中所拥有的东西,以在您的venv文件夹中创建一个framework bash文件,并通过它运行命令.

I just discovered that matplotlib has issue with virtual environments. I tried the solutions in the FAQs but they didn't work. An ideal solution should only involve pip commands, but it might be hard or unrealistic to request that. Anyway, I tried what they had on the OS X section to make a framework bash file in your venv folder and run command through it.

$ frameworkpython krls.py

当我这样做时,出现权限拒绝错误:

when I did that I got a permission deniel error:

Permission denied

我有点害怕命令我不是100%地执行命令...无论如何,看来bash脚本并没有做任何太危险的事情,所以我继续对它进行了sudo-ed操作.但是,我的终端的响应很奇怪,它说:

I am sort of scared of sudoing commands that I am not 100% what they do...anyway, it seemed the bash script isn't doing anything too dangerous so I went ahead and sudo-ed it. However, the response of my terminal was weird, it said:

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

表示它不能将frameworkpython识别为命令.如果没有sudo,它会说:

which means it doesn't recognize frameworkpython as a command. Without the sudo it says:

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

frameworkpython krsl.py -bash: /Users/my_name/path/venv/bin/frameworkpython: Permission denied

似乎可以将frameworkpython识别为命令(?),但是由于权限的原因它没有执行?对我来说似乎很奇怪.任何想法吗?

which seems it recognizes frameworkpython as a command (?) but it didn't execute it due to permissions? It seems strange to me. Anyone any ideas?

我也尝试过:

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

但是没有用.

所以我尝试了使用PySide的下一个选项,该选项也不起作用,并给出了巨大的错误输出:

So I tried the next option which is using PySide which also didn't work and gave a giant error output:

$ 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 尝试下一个选项.不幸的是,我浏览了他们的网站,找不到如何做.

After that then I tried the next option using WX Phonix. Unfortunately, I went through their site and couldn't find how to do it.

推荐答案

更新:

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

With Python3, you can use the built-in implementation of virtualenv via -m venv:

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

Python3的内置实现构建了virtualenv,从而将Python设置为框架,因此无需进行任何配置即可使其工作. 此处.

Python3's builtin implementation builds the virtualenv such that Python is set up as a framework, so no need to configure anything to get it to work. More details here.

原始答案:

您引用的常见问题解答所述,您将需要创建一个venv/bin中的frameworkpython脚本.看来您的系统找不到frameworkpython,所以它不在您的系统$PATH上,或者它不是可执行文件.

As stated in the FAQS you reference, you will need to create a frameworkpython scripts in venv/bin. It looks like your system is unable to find frameworkpython so it is either not on your systems $PATH or it is not executable.

确保通过chmod +x venv/bin/frameworkpython使此脚本可执行!

Make sure you make this scripts executable via chmod +x venv/bin/frameworkpython!

来自 Linux/Unix文档(我加粗了):

PATH是Linux和其他类似Unix的操作系统中的环境变量,它告诉外壳程序要搜索可执行文件文件的目录.

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

Your system will only look for executable files accessible via the PATH environment variable, skipping over non-executable files.

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

Creating the frameworkpython script is necessary because matplotlib requires a framework build of python. From the link above:

不幸的是,即使从Python的框架版本中创建,virtualenv仍会创建非框架版本.

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

这是另一篇帖子有关框架构建的更多详细信息

Here's another post with more details on framework builds

这篇关于使OSX中的matplotlib在虚拟环境中工作的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆