0

I have get a virtual env on '/home/name/pyenv' for python2.7.9; Now I want to install 'matplotlib' for it; then I activate this virtual env and install 'matplotlib' as below:

  • by command "sudo apt-get install python-matplotlib"; (if delete "sudo", permission denied), it runs well and I find "matplotlib" is exactly installed, but it is for default python and not for virtual env(pyenv) ;
  • by command "pip install matplotlib"

    I get error as below:

                    * The following required packages can not be built:
    
                    * freetype
    

Cleaning up... Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-tYCFkL/matplotlib Exception information: Traceback (most recent call last): File "/home/caofa/odoo-9.0/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/home/caofa/odoo-9.0/local/lib/python2.7/site-packages/pip/commands/install.py", line 290, in run requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File "/home/caofa/odoo-9.0/local/lib/python2.7/site-packages/pip/req.py", line 1230, in prepare_files req_to_install.run_egg_info() File "/home/caofa/odoo-9.0/local/lib/python2.7/site-packages/pip/req.py", line 326, in run_egg_info command_desc='python setup.py egg_info') File "/home/caofa/odoo-9.0/local/lib/python2.7/site-packages/pip/util.py", line 716, in call_subprocess % (command_desc, proc.returncode, cwd)) InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-tYCFkL/matplotlib

I want to install it by method 1, but i don;t know how to install it for virtual env.

vx2008
  • 95
  • 1
  • 1
  • 10

2 Answers2

1

when working in venv then try to used pip for installation for python packages ,sudo apt-get install normally using for root user of Linux. for your case you could try pip install matplotlib==2.2.5

Ahmed Salman
  • 241
  • 2
  • 7
0

One possibility is to install matplotlib globally then create your virtualenv with the site packages, see here for someone with exactly the same problem, by using virtualenv --system-site-packages you can then activate your virtualenv and add additional packages, or update them, within your virtualenv only.

I am reasonably sure that you can even uninstall globally installed packages within your virtualenv without impacting your global installation but suggest you pick a small package that you can easily reinstall to test this on early on.

Community
  • 1
  • 1
Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
  • thanks for your advice; do you mean that I should apt-get install matplotlib in command windows; then" virtualenv somedir --system-site-packages"; then somedir virtual env will can use the matplotlib? but I want to know whether we can install something by "apt-get install somepackage" only for some certain virtual env? – vx2008 Jul 31 '16 at 11:27
  • `sudo apt-get install` will do a global _or user scope_ install - as it is not a part of the python "ecosystem" it does __not__ respect `virtualenv.` – Steve Barnes Jul 31 '16 at 11:31