I can't use pip on WSL Ubuntu - python

If I try to download Python packages with pip, following error messages come out.
nblizz#NBLIZZ-PC:~# pip3 install flask-restful
Collecting flask-restful
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', OSError(0, 'Error'))': /simple/flask-restful/
Could not find a version that satisfies the requirement flask-restful (from versions: )
No matching distribution found for flask-restful
None of these solutions work.
Re-install pip
Re-install WSL
sudo pip3 install [package]
pip3 install [package] with root account
sudo -H pip3 install [package]
pip install --user [package]
How do I install pip packages without errors?

Update your pip: python -m pip install –upgrade pip; If its already updated proceed with any of the below two methods:
Method - I
You can download binary files from the below link
https://www.lfd.uci.edu/~gohlke/pythonlibs/
Once the desired module (.whl file) is downloaded, open the command prompt on the downloaded location (you can do that by pressing shift + right click; select open command prompt/powershell here) and type pip install your-package.whl
Method - II
Go to https://pypi.org/ and search for the desired package.
Once downloaded, copy the package in the site-packages directory manually.
There are standard locations for site-package:
Unix(pure): prefix/lib/pythonX.Y/site-packages
Unix(non-pure):exec-prefix/lib/pythonX.Y/site-packages
Windows:prefix\Lib\site-packages
To verify the download, by either of these methods, use the import statement on your console.

I use google to search: pip ProtocolError
Someone said that:
SOLVED The issue was that my dorm firewall is blocking pip (pypi.python.org). Issuing the same command at work installs python packages correctly.
see: PIP not working - proxy - Connection aborted
If this solution still not work for you, please tell more about your machine like
pip --version, pip3 --version, python3 -V, python -V, cat /etc/issue

The cause was my Kaspersky application. It blocks every pip/curl executions.

I had a similar but not identical problem with pip in WSL. (There is a diffrent error message).
$ pip3 install pytest
Collecting pytest
Cache entry deserialization failed, entry ignored
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23344eb8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e748>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e940>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7e390>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3b23a7eb00>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/
Could not find a version that satisfies the requirement pytest (from versions: )
No matching distribution found for pytest
It turned out the WSL could't connect to any DNS server. ping 8.8.8.8 -c 1 was successful, but ping www.google.com -c 1 resulted in Temporary failure in name resolution. The reason for this was that /etc/resolv.conf was corrupted. I fixed it by replacing the corrupted content with the content below:
# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
8.8.8.8
4.4.4.4
(Use e.g. nano for editing: sudo nano /etc/resolv.conf). I used Google's DNS servers above. WSL should update the DNS server automatically if the first line is included. After this pip worked normally again for me.

I faced the same issue on WSL1 using conda environments. Eventually I found out that the solution is to have the same python version in conda's base environment as in the conda environment from which the pip install commands are being triggered.
sudo pip install should be avoided (even if as it seemingly solves the NewConnectionError error), as it will install packages globally and will mess up conda environments.

Two issue that typcially get overlooked for me.
Add public dns entry to /etc/resolv.conf
nameserver 8.8.8.8
This will be overwritten on next startup unless you create a /etc/wsl.conf file with the below
[network]
generateResolvConf = false
The first issue is typically only a problem if wsl and windows have a time drift.
From Powershell...
Get-Date; wsl date
If your output doesn't match give it good old reboot. Usually fixes the issue for me.

Tried all solutions, what solved the issue for me is to update the wsl by running from Windows CMD
wsl --update

Related

Error while installing stable-baselines in Kaggle

i'm trying to run some machine learning environment on Kaggle, but i can't install the packages... I Need to install stable-baselines3[extra] but i cant. I tried with
pip install stable-baselines3[extra]
but i get this error:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection
object at 0x7f8159233e50>: Failed to establish a new connection: [Errno -3] Temporary failure
in name resolution')': /simple/stable-baselines3/
How to resolve this?

pip: unable to skip build dependencies for ibm-db

I'm trying to get Python's IBM DB2 package 'ibm-db' up and running, but my efforts keep failing so far. The problem is that I'm behind a corporate proxy which apparently prevents downloads of dependencies needed for package installation. The command I used is:
pip --trusted-host pypi.org --trusted-host files.pythonhosted.org install --proxy=http://<host>:<port> ibm-db
This successfully downloads the package and then tries to install some build dependencies:
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [9 lines of output]
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B0F00AEE60>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B0F00AE200>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B0F00ACEB0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B0F128C070>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000001B0F128E9B0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/setuptools/
AFAIK, the only dependency is DB2 ODBC CLI driver. ibm-db's installation instruction says you could skip that depenedency by installing ODBC CLI manually and then setting IBM_DB_HOME env variable to its installation directory - which I did, but without success. Pip still tries to download and install the dependency. I also used the --no-deps flag to keep pip from downloading it, but again without success.
So, is there another way to forcefully prevent dependency installation or make build dependencies work behind a proxy?
Btw: I'm using Python 3.10.5 and pip 22.0.4
EDIT: The OS is Win 10, so the CLI driver has been set using control panel. Installation is local.

Pip not getting installed

C:\Python>python get-pip.py
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000002EDF31D2AD0>, 'Connection to 10.1.1.9 timed out. (connect timeout=15)')': /simple/pip/
Screenshot of the error message
I'm trying to install pip on my windows 11. I have navigated to the directory in which Python is installed. And yet, I am constantly getting the same error again and again. I haven't configured anything yet. Please guide me through the complete procedure right from the beginning by installing python.

Error to install packages in python Computer without a network ( Errno 11001)

strong textI manually install package as follows:
pip install C:\Users\AAA PC\Desktop\selenium.whl
I get the following error:
Collecting requests
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0424C6F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E150>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E230>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E310>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0426E3F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/requests/
Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
First upgrade:
python -m pip install --upgrade pip
Then, enter in the terminal:
pip install -U selenium
pip install "C:\Users\AAA PC\Desktop\selenium.whl"
This should install from any directory.
An important thing worthy of noting is the .whl file name should not be renamed from the original. For example, if you want to install .whl for the selenium module, I believe the original name of the file is "selenium-3.141.0-py2.py3-none-any.whl" (as per PyPI)
Hence you need to rename the file to the original name and install using
pip install "C:\Users\AAA PC\Desktop\selenium-3.141.0-py2.py3-none-any.whl"
else you could see errors like "ERROR: selenium.whl is not a valid wheel filename"
Also, your error says, collecting requests.
This tells the python is having issues downloading the requests module, not with the selenium module. Hence you could first install requests.whl and then try installing selenium
First make sure pip is up to date using this command:
python -m pip install --upgrade pip
Then run to install the wheel file, run this command:
pip install "C:/Users/AAA PC/Desktop/selenium.whl"
However, this is not the original name of the wheel file. The official wheel name, from PyPi is:
selenium-3.141.0-py2.py3-none-any.whl
So you should delete that file and reinstall it from PyPi. You'll end up with this command:
pip install "C:/Users/AAA PC/Desktop/selenium-3.141.0-py2.py3-none-any.whl"
How about instead of using Pip, use setup.py. If you download the selenium tarball you can run python setup.py install from within the uncompressed directory of the tar file.

Issue with installing packages on virtual environment created by anaconda

I installed anaconda on a sandbox in my work and trying to install tensorflow. I ran below command and run into issue.
(venv) [root#box4 venv]# pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp36-cp36m-linux_x86_64.whl
Collecting tensorflow-gpu==1.4.0 from https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp36-cp36m-linux_x86_64.whl
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6304ba9e80>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp36-cp36m-linux_x86_64.whl
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6304ba9f28>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp36-cp36m-linux_x86_64.whl
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f6304b5c048>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp36-cp36m-linux_x86_64.whl
^COperation cancelled by user
I tried below command to check if internet is available on that box
(venv) [root#gmc4bayer venv]# ping storage.googleapis.com
PING storage.l.googleusercontent.com (172.217.12.48) 56(84) bytes of data.
^C
--- storage.l.googleusercontent.com ping statistics ---
19 packets transmitted, 0 received, 100% packet loss, time 17999ms
I am trying to find dest IP and any port(s) required so that I can ask my network admin to whitelist it. I might have to install lot of other packages. Do I have to find IPs for all those websites also and whitelist them? Wondering if there is a clean and easy way to resolve this issue
Any one ran into this issue?
I recommend you to use Anaconda Navigator to install packages.

Categories

Resources