11
$ sudo pip install numpy    # or anything else

error:

The directory '/home/user/.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. (tried sudo -H, the rest errors persist)  
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.    
Collecting numpy  
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/numpy/  
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.  
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping  
$ python -V
Python 3.7.3  
$ pip -V
pip 19.0.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
$ whereis pip
pip: /usr/local/bin/pip2.7 /usr/local/bin/pip3.7 /usr/local/bin/pip /usr/local/bin/pip3.6  

pip3.6 appeared after:

$ sudo su
$ update-alternatives --install /usr/bin/python python /usr/bin/python3 1

In anaconda environments, pip works fine.

Is deleting things related with python, at a safe extend - without breaking the system, and re-install stuff properly, a preferable solution? And how to do so?

I know that there are a lot of similar questions, but I've tried a lot of stuff (obviously, I messed something) and I haven't solve the problem.

Thanks!

vidarlo
  • 22,691
Thanasis Mattas
  • 225
  • 1
  • 2
  • 8

1 Answers1

9

1- Avoid to use sudo when you don't need to.
2- Since you're using Python3, the appropriate way the install a package in Python3 is using pip3.
So the command will be as follows: pip3 install --user <package_name> Where:

  • pip3 is for Python3.

  • install to install a package using pip3.

  • --user to save that downloaded package in the current user directory (so you'll not need more privileges).

  • package_name any Python package.

EDIT:
1. Install the necessary packages for Python and ssl: sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

  1. Download and unzip "Python-3.7.0.tar.xz" from https://www.python.org/ftp/python/ into your home directory.

  2. Open terminal in that directory and run: ./configure

  3. Build and install: sudo make && sudo make install

  4. Install packages with: pip3 install package_name

singrium
  • 6,880
  • 1
    Tried without sudo and with pip3 and got the same [pip is configured with locations that require TLS/SSL...] error. – Thanasis Mattas Aug 09 '19 at 17:13
  • 2
    @Thanasis I edited my answer, please try it then tell me if anything occurs – singrium Aug 09 '19 at 21:11
  • 3
    Yes, that worked! Thanks a lot! – Thanasis Mattas Aug 10 '19 at 14:55
  • 3
    So, the solution to an ubuntu packaging problem, is to install from source? That can't be right. – mcr Feb 11 '20 at 16:09
  • Whenever I do sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev I get E: Unable to correct problems, you have held broken packages. Please help I am getting the ssl error whenver I use pip3 – nkhl Aug 05 '20 at 13:30
  • You have some broken packages. Try: sudo apt install --fix-broken to fix the installation – singrium Aug 05 '20 at 13:46
  • 1
    Yo, this worked for me on Kali. Thanks. – DevOpsSauce Jun 12 '21 at 19:32
  • if I installed python from somewhere else where do I run the configure command? – Eduardo Wada Feb 14 '23 at 22:17
  • 1
    In addition to @singrium answer. libreadline-gplv2-dev appears to have been dropped and so you can remove it when running the command provided – davidn Mar 23 '23 at 12:51
  • Manually compiling and installing Python from source isn't a solution. It's a workaround. – Vince May 11 '23 at 14:12