When creating a virtual environment, it may be created with virtualenv. For example, it looks like the following.
However, in the virtual environment created in this way, an error may occur when importing a module such as matplotlib.pyplot
. I get an error when trying to use macosx backend.
$ virtualenv --python=`which python3.5` --system-site-packages viz
$ . ./viz/bin/activate
(viz)$ python -c 'import matplotlib.pyplot'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ
-m venv
instead of virtualenvFrom around python3.3, the python standard library itself has a function to execute a virtual environment. Use this to create a virtual environment.
$ python -m venv --system-site-packages viz2
$ . ./viz2/bin/activate
(viz2)$ python -c 'import matplotlib.pyplot'
Play with PYTHON HOME.
(viz)$ deactivate
$ which python
/opt/local/bin/python
$ . viz/bin/activate
(viz)$ PYTHONHOME=$VIRTUAL_ENV /opt/local/bin/python -c 'import matplotlib.pyplot'
If you put a link. link This information should be transmitted to those who read the previous article.
-What to do if matplotlib.pyplot cannot be used when building an environment with pyenv and virtualenv --Qiita -Solution when you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3 --Qiita -Resolve Matplotlib Runtime Error --Qiita -Until you install and run matplotlib-- Qiita --Matplotlib etc. cannot be imported in VirtualEnv environment --Qiita -Memo I was addicted to when inserting matplotlib --Qiita
Recommended Posts