0

I tried

sudo apt-get install python3
sudo apt-get install idle
sudo apt-get install python3-pip

then I try to install modules with pip, I tried several non work.

pip install send2trash
Collecting send2trash
  Downloading https://files.pythonhosted.org/packages/13/2e/ea40de0304bb1dc4eb309de90aeec39871b9b7c4bd30f1a3cdcb3496f5c0/Send2Trash-1.5.0.tar.gz
Building wheels for collected packages: send2trash
  Running setup.py bdist_wheel for send2trash ... done
  Stored in directory: /home/joe/.cache/pip/wheels/f1/ca/e5/bdd5eae705cf50a483257e6ff9dd34911dda3570f0e1340dda
Successfully built send2trash
Installing collected packages: send2trash
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/Send2Trash-1.5.0.dist-info'
Consider using the `--user` option or check the permissions.

You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

So I tried upgrading pip ...

sudo pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

Apparently, I have some old python 2.7 on my computer. I am not using it. If the solution involves uninstalling that, it's okay by me. Thanks in advance.

Also just tried sudo pip3 as I read in some instructions. Here's what I get now...

sudo pip3 install beautifulSoup
[sudo] password for joe: 
The directory '/home/joe/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/joe/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting beautifulSoup
  Downloading https://files.pythonhosted.org/packages/1e/ee/295988deca1a5a7accd783d0dfe14524867e31abb05b6c0eeceee49c759d/BeautifulSoup-3.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-p5xsk9e4/beautifulSoup/setup.py", line 22
        print "Unit tests have failed!"
                                      ^
    SyntaxError: Missing parentheses in call to 'print'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-p5xsk9e4/beautifulSoup/
You are using pip version 8.1.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Message says that /home/joe/.cache/pip/http is not owned by current user. That is so not true. My computer lies to me. This whole path all the way down is owned by me, user joe.

here is run with sudo pip ...

sudo pip install beautifulSoup
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

I ran ...

sudo python3 -m pip install --upgrade pip
The directory '/home/joe/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/joe/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 553kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

This seemed to work. But then I ran sudo pip3 and sudo pip ...

sudo pip3 install beautifulSoup
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal import main
ImportError: No module named 'pip._internal'

sudo pip install beautifulSoup
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named 'pip._internal'
JoeM
  • 29
  • 1
  • 10
  • 2
    Try using `python3 -m pip install ...` to install packages. And as far as I recollect you get `pip3` when you install python. So you can install packages with `pip3 install ...` – sP_ Aug 08 '18 at 19:37
  • 2
    You can try using `pip3`, not `pip` for Python3, as `pip` might refer to Python2 which is still on your system. – dmitryro Aug 08 '18 at 19:38
  • **sudo python3 -m pip install --upgrade pip** – Chetan_Vasudevan Aug 08 '18 at 19:39
  • I would do yourself a favor and dump python 2.7 off your computer. I suspect down the road you are going to run into other weird stuff with packages having similar problems. – sniperd Aug 08 '18 at 19:42
  • the issue about permissions concerns the cache of the download data (as that must have been created when running a command as root) but pip will work this out and has just re-downloaded it – Joe Iddon Aug 08 '18 at 19:46
  • 1
    Is uninstalling python 2.7 really a good idea? Per this thread ... https://askubuntu.com/questions/187227/i-run-sudo-apt-get-remove-python2-7-can-i-restore-my-ubuntu-now#199435 and from this thread https://stackoverflow.com/questions/44602191/how-to-completely-uninstall-python-2-7-13-on-ubuntu-16-04 – JoeM Aug 08 '18 at 20:04
  • I tried `sudo python3 -m pip install --upgrade pip` and I now get no module name pip._internal. Sorry but this is a huge step backward. – JoeM Aug 08 '18 at 20:08
  • `sudo apt-get install python3-bs4` is your another option on Ubuntu - see here in more detail https://stackoverflow.com/questions/26511791/ubuntu-how-to-install-a-python-module-beautifulsoup-on-python-3-3-instead-of – dmitryro Aug 08 '18 at 20:11
  • Possible duplicate of [Error after upgrading pip: cannot import name 'main'](https://stackoverflow.com/questions/49836676/error-after-upgrading-pip-cannot-import-name-main) – anthony sottile Aug 11 '18 at 18:25

2 Answers2

0

Ok, first let's fix your Pip install:

sudo apt-get install --reinstall python3-pip

Now you should be able to run pip3 --version to check that Pip is installed and working properly. If not, let me know before you try anything else.

Key points to note:

  • When running Pip outside a virtualenv, you'll need to use pip3, otherwise your system will try to use Python 2's Pip.
  • If you ever need to run Pip as root, it's best to use sudo -H rather than just sudo – this will fix the warnings about The directory ... is not owned by the current user.

If you want to install Pip 18, I would recommend doing so in a virtualenv – upgrading the system Pip is fraught with things that can go wrong.

e.g.:

# Create a new virtualenv:
python3 -m venv my_virtual_environment
# "Activate" it (you need to do this once per shell)
source my_virtual_environment/bin/activate
# Now you can use `pip`, `python` etc. and the changes will be kept in the `my_virtual_environment` directory
pip install -U pip setuptools wheel

Also, to install BeautifulSoup, you need the beautifulsoup4 package – beautifulSoup is old and doesn't work with Python 3:

pip install beautifulsoup4
ash
  • 5,139
  • 2
  • 27
  • 39
  • 1
    Hi Josh, @Josh Installed python3-pip with no incident. Unfortunately, I get this on pip3 --version: ` pip3 --version Traceback (most recent call last): File "/usr/local/bin/pip3", line 7, in from pip._internal import main ImportError: No module named 'pip._internal'` – JoeM Aug 08 '18 at 22:42
  • Hmm. Can you run `sudo mv /usr/local/bin/pip{,.old}` and `sudo mv /usr/local/bin/pip3{,.old}` and see if it works then? – ash Aug 09 '18 at 08:01
-1

You are receiving the error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/Send2Trash-1.5.0.dist-info'

because you are running pip install under a normal user.

You can either run this same command with sudo pip install 'packagename'. This will give you root privileges when installing, or you can check out running this in a virtualenv. You can read up more on virtualenv at here.

whoosis
  • 454
  • 7
  • 25
  • 1
    Thank you, I just caught that too. I added into post, what happens with sudo pip3. and sudo pip. – JoeM Aug 08 '18 at 19:45