1

Trying out a pycon tutorial on machine learning and was installing the required packages. Had some problem and accidentally installed without going into my virtualenv. Tried to uninstall matplotlib, numpy, scipy and more without any success as it gave me very long error message.

However, in python, I cannot import matlibplot as I get the following error:

import matplotlib Traceback (most recent call last): File "", line 1, in File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/site-packages/matplotlib/init.py", line 1131, in rcParams = rc_params() File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/site-packages/matplotlib/init.py", line 975, in rc_params return rc_params_from_file(fname, fail_on_error) File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/site-packages/matplotlib/init.py", line 1100, in rc_params_from_file config_from_file = _rc_params_in_file(fname, fail_on_error) File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/site-packages/matplotlib/init.py", line 1018, in _rc_params_in_file with _open_file_or_url(fname) as fd: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in enter return self.gen.next() File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/site-packages/matplotlib/init.py", line 1000, in _open_file_or_url encoding = locale.getdefaultlocale()[1] File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/locale.py", line 543, in getdefaultlocale return _parse_localename(localename) File "/Users/zhangsheng/Desktop/PYTHON/scikit/sk/lib/python2.7/locale.py", line 475, in _parse_localename raise ValueError, 'unknown locale: %s' % localename ValueError: unknown locale: UTF-8

I'm quite new to stuff like this and really need help for my problem here. Many thanks :)

I'm on a mac and I used pip to install these packages

pip install matplotlib

then uninstalling by using

pip uninstall matplotlib

Initially when i was installing in the a virtualenv I encountered a problem in installing seaborn after installing matplotlib, scipy, numpy, scikit-learn, ipython. So I uninstalled matplotlib and then installed seaborn before reinstalling matplotlib

Edit: As I tried to uninstall those packages mentioned above, I realised that I can import matplotlib in my python without virtual env. However, if I was to create a virtual env using virtualenvand install matplotlib, it can't be imported in the virtual enviroment. Does anyone have a solution to my problem?

Zhangsheng
  • 85
  • 2
  • 11
  • How did you install the packages? How did you try to uninstall the packages? Please edit your post to include these details with actual commands. – wflynny Jan 13 '16 at 15:32

2 Answers2

1

Your error has little to do with Python, but rather your shell environment. Simply add these two lines to your ~/.profile and restart the terminal:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

If you don't have a ~/.profile, you can safely create it - again, from the terminal:

vim ~/.profile

If you are new to vim, follow these steps:

  1. Hit ESC (to clear the screen)
  2. Hit i (for insert mode)
  3. Copy and paste those lines
  4. Hit ESC
  5. Type the following keys, in sequence :wq and hit enter
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • does the `~/.profile` refer to my username? How do I know if I have a profile? Many thanks :) – Zhangsheng Jan 14 '16 at 05:54
  • The `~` is a shortcut to your home directory. If you have one, the file will contain information. If its blank, that's okay too. There is a global profile that is applied to all accounts, and it is overridden if there is a local `.profile` file in the user's home directory. – Burhan Khalid Jan 14 '16 at 05:55
  • I followed your instructions but I still can't uninstall those packages. Just to check if what I did was correct, type vim ~./profile (as it is, I didn't replace the profile word), follow steps 1-5 as shown above. – Zhangsheng Jan 14 '16 at 06:42
  • After you have done those steps; close the terminal and re-open it again. You need to quit it completely. Or, you can type `source ~/.profile` – Burhan Khalid Jan 14 '16 at 07:34
  • It doesn't seem to be working for me... Just to add, I'm using the python that comes pre-installled with the OS. Could this be the reason that I can't uninstall? If i remember correctly, I might have used `sudo pip install` for the installation; would this have contributed to this problem? If possible, could you elaborate on the problem on my shell environment and what might have caused this so I can have a better understand and prevent this from happening in future. – Zhangsheng Jan 14 '16 at 08:45
0

Open Command, cmd or Dos and type this:

pip install matplotlib

then try to import again

Edit: if you want to uninstall you just need to delete the package from your python's site-packages directory C:\Python27\Lib\site-packages just delete them from there.

Edit: by 'Them' i meant those packages that you don't need. if you couldn't find them probably it didn't install in first place.

Edit: that's what i get in sit-packages after reinstalling python: enter image description here

Bear
  • 550
  • 9
  • 25
  • Thanks for your suggestions. I did that before in my virutalenv and I think it was quite successful. However, I want my python to have only the default packages and no extra packages other than `pip` and `virtualenv`. Therefore I'm wondering which are the default packages that comes with python. – Zhangsheng Jan 13 '16 at 15:52
  • @zunct10n i'm not sure too, but if you ask me, i would check the date of creation of each folder or uninstall python and delete it from root drive and reinstall it. – Bear Jan 13 '16 at 15:56
  • I tried to do what u suggested; find the date of creation, but the date of creation is not the date which I downloaded it but the date the folder was created. Regardsing uninstalling python, it is really not an option as it is a Apple supplied python which will cause my mac to brick if I really did that. – Zhangsheng Jan 14 '16 at 05:45
  • @zunct10n okay i edited my comment, maybe that help you out. – Bear Jan 14 '16 at 06:46
  • I think there's a difference for my python as I'm on a mac and the python I'm using comes pre-loaded with it by Apple. Thus I can't really reinstall python. – Zhangsheng Jan 14 '16 at 06:49
  • @zunct10n: have you try this? http://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4 then to install again: http://www.pyladies.com/blog/Get-Your-Mac-Ready-for-Python-Programming/ – Bear Jan 14 '16 at 06:57
  • Haha. I have seen that before. It was from there that I read that it will break my mac if I uninstalled it. – Zhangsheng Jan 14 '16 at 07:01
  • i see... I afraid i have no any other solution for this issue. maybe try edit your question and tag your operation system. could catch attention of people expert in that area. – Bear Jan 14 '16 at 07:13
  • Thanks for your help and advice. Will do so. – Zhangsheng Jan 14 '16 at 07:14