Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the simplest way to make matplotlib in OSX work in a virtual environment?

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

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

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

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

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?


I also tried:

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

but it didn't work.

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/

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.

like image 683
Charlie Parker Avatar asked Jun 29 '16 04:06

Charlie Parker


1 Answers

Update:

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'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.


Original Answer:

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.

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

From Linux/Unix docs (I added the bold):

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

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


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

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

like image 182
Pedro Cattori Avatar answered Sep 28 '22 11:09

Pedro Cattori