Title: BeautifulSoup 4 Install Error by typing pip install --upgrade beautifulsoup4
Tags: python-3.x;beautifulsoup;failed-installation
Question: I tried to install BeautifulSoup 4 

It worked after I typed following into my mac terminal

```$ easy_install beautifulsoup4
$ pip install beautifulsoup4
```

But when I imported it in my python, 

```from bs4 import BeautifulSoup
```

the screen always shows the Error:

```ImportError: cannot import name 'HTMLParseError'
```

Then I googled the error and found by typing following code in terminal could solve the problem

```pip install --upgrade beautifulsoup4
```

But after I typed,it was shown 
Exception:

```Traceback (most recent call last):
  File "//anaconda/lib/python3.5/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "//anaconda/lib/python3.5/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "//anaconda/lib/python3.5/site-packages/pip/req/req_set.py", line 742, in install
    **kwargs
  File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "//anaconda/lib/python3.5/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 346, in move_wheel_files
    clobber(source, lib_dir, True)
  File "//anaconda/lib/python3.5/site-packages/pip/wheel.py", line 324, in clobber
    shutil.copyfile(srcfile, destfile)
  File "//anaconda/lib/python3.5/shutil.py", line 115, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '//anaconda/lib/python3.5/site-packages/bs4/__init__.py'
```

I have no idea how to fix it. Thanks for someone help

Comment: What's the output of `ls -l //anaconda/lib/python3.5/site-packages/bs4/`?

Here is the accepted answer: Easiest way to solve this is using Sudo.


    sudo pip install --upgrade beautifulsoup4
  

However sudo is not always recommended to do so, you should not install arbitrary code as root. 

My recommendation would be to create a virtualenv, install the packages play with before using sudo to install them as root. 

You can use virtualenvwrapper 


sudo pip install virtualenvwrapper
mkvirtualenv
workon
python setup.py install




{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:06/06/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python-3.x><beautifulsoup><failed-installation>', 'Title': 'BeautifulSoup 4 Install Error by typing pip install --upgrade beautifulsoup4', 'ViewCount': 4120, 'id': 37659721, 'user_AboutMe': None, 'user_AccountId': 8584019.0, 'user_DisplayName': 'becks', 'user_Reputation': 3.0, 'user_Views': 2.0, 'user_id': 6430780.0}}