0

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.

  • How do you know the file is locked. The suggestions do not deal with a locked file – user151019 May 23 '16 at 12:38
  • Is your user name the results of the command- id -un? – fd0 May 23 '16 at 12:51
  • When I open the .bash_profile It doesn't let me to write anything in it and above the window it's written locked. Also when I want to unlock it says I don't have the permission. So I found that I should give myself permission through terminal but couldn't since it says illegal username(maybe the command is not right, but I don't know any other way to unlock it) – Amin Shn May 23 '16 at 12:54
  • This Is what I see: amins-MacBook-Pro:~ aminsh$ sudo chown amins-MacBook-Pro ~/.bash_profile Password:(I write my password here but it doesn't show anything however when I press enter I see the next line) chown: amins-MacBook-Pro: illegal user name – Amin Shn May 23 '16 at 12:57
  • 1
    First of all ~/.bash_profile does not exist by default. Secondly if it was created normally, by you, then you should already own it and it shouldn't be locked. What's the output of: ls -leO@ ~/.bash_profile If the output has uchg in it then use this command to unlock it: chflags nouchg ~/.bash_profile – user3439894 May 23 '16 at 13:05
1

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.

  • This is what I see again : amins-MacBook-Pro:~ aminsh$ chown $(id -u -n) .bash_profile chown: .bash_profile: Operation not permitted amins-MacBook-Pro:~ aminsh$ chown $(id -u -n) ~/.bash_profile chown: /Users/aminsh/.bash_profile: Operation not permitted – Amin Shn May 23 '16 at 13:02
  • You should add a note about using sudo with chown when the target is not presently owned by the $USER trying to change the ownership of the target filename. – user3439894 May 23 '16 at 13:18
  • You might add the following from the chown man page- For obvious security reasons, the ownership of a file may only be altered by a super-user. – fd0 May 23 '16 at 13:32
0

Have you tried editing the bash_profile from the home directory? This honestly shouldn't be locked for any reason. The simple gui approach here would be to unlock via get info in finder (I'm assuming you're on a mac).

  • This issue was previously resolved. The file was owned by root instead of by the user who was trying to edit it. – tubedogg Oct 22 '16 at 4:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .