How can I edit the .bash_profile? I want to use matplotlib in Python, but it gives me this error:


  ValueError: unknown locale: UTF-8


So I searched the internet and people suggest that I should edit my .bash_profile. But when I open it I can't edit since it is locked! So I searched about unlocking .bash_profile, this time people suggest using this command in terminal:

sudo chown My username ~/.bash_profile


But after entering my password, it says:


  chown: My username: illegal user name


Why does it say my user name is illegal? I have no idea what to do about. I would appreciate if someone can help me.
Try the following command:

chown $(id -u -n) ~/.bash_profile


Using the chown command in that way, you can be sure that is using your username (id -u -n).

Additionally, as @user3439894 says, if you get permission errors with previous command, your should add sudo before the command to execute the command as root:

sudo chown $(id -u -n) ~/.bash_profile


From id man page:


  id - print real and effective user and group IDs
  
  -n, --name: print a name instead of a number
  -u, --user: print only the effective user ID


From chown man page (suggested by @fd0):


  For obvious security reasons, the ownership of a file may only be altered by a super-user.