nltk.download() connection reset by peer error - m1 macbook air - nlp

I am unable to download nltk's punkt package by using the following command after importing nltk.
nltk.download('punkt')
The error I get is:
[nltk_data] Downloading package punkt to /Users/name/nltk_data...
[nltk_data] Error downloading 'punkt' from
[nltk_data] <https://raw.githubusercontent.com/nltk/nltk_data/gh-
[nltk_data] pages/packages/tokenizers/punkt.zip>: [Errno 54]
[nltk_data] Connection reset by peer
I have tried using the wizard that comes after nltk.download() and that also gave me the connection reset by peer error.

Related

manually download pytorch and feed downloaded path to anaconda

I tried to conda install pytorch ... but it doesn't even start and gives me
("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
I'm thinking to download the necessary file manually(safe download even if internet is slow) and then set it to anaconda so that installs directly from downloaded file instead of downloading it self
This can be done by downloading pip wheels for torch, torchvision and torchaudio etc. and doing pip installation for local wheels. Suitable Pytorch wheels can be downloaded from here. Now, you can simply pip install the downloaded whl files:
pip install file.whl
Here file.whl is the downloaded wheel.

Problems creating a python package using setuptools and trying to install it from local filesystem

I have created a small package and I'm trying to install it from the local file system but things are not working as expected.
So, let's start with my repository structure
python
packages
myapiclient
myapi
__init__.py
apiclient.py
requirements.txt
setup.py
The init file is empty.
apiclient.py
class APIClient(object):
pass
setup.py
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
setup(
name='myapi',
version='0.1.0',
description='MyApi API client',
author='Giuliani D. Sanches',
author_email='myemail#someprovider.com',
packages=find_packages(exclude=('tests', 'docs')),
install_requires=['requests']
)
To install my package using a virtualenv I run the following pip install command but it finish with an error:
(.vevn) $ pip install --upgrade --no-index --find-links /lib-repository/python/packages/myapiclient/ myapi
Looking in links: /lib-repository/python/packages/myapiclient/
ERROR: Could not find a version that satisfies the requirement myapi (from versions: none)
ERROR: No matching distribution found for myapi
Doing a setup.py install seems to work:
(.venv) $ python3 /lib-repository/python/packages/myapiclient/setup.py install --force
output
running install
running bdist_egg
running egg_info
writing myapi.egg-info/PKG-INFO
writing dependency_links to myapi.egg-info/dependency_links.txt
writing requirements to myapi.egg-info/requires.txt
writing top-level names to myapi.egg-info/top_level.txt
reading manifest file 'myapi.egg-info/SOURCES.txt'
writing manifest file 'myapi.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
warning: install_lib: 'build/lib' does not exist -- no Python modules to install
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying myapi.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying myapi.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying myapi.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying myapi.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying myapi.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/myapi-0.1.0-py3.8.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing myapi-0.1.0-py3.8.egg
Copying myapi-0.1.0-py3.8.egg to /lib-repository/.venv/lib/python3.8/site-packages
Adding myapi 0.1.0 to easy-install.pth file
Installed /lib-repository/.venv/lib/python3.8/site-packages/myapi-0.1.0-py3.8.egg
Processing dependencies for myapi==0.1.0
Searching for requests==2.27.1
Best match: requests 2.27.1
Adding requests 2.27.1 to easy-install.pth file
Using /lib-repository/.venv/lib/python3.8/site-packages
Searching for idna==3.3
Best match: idna 3.3
Adding idna 3.3 to easy-install.pth file
Using /lib-repository/.venv/lib/python3.8/site-packages
Searching for charset-normalizer==2.0.10
Best match: charset-normalizer 2.0.10
Adding charset-normalizer 2.0.10 to easy-install.pth file
Installing normalizer script to /lib-repository/.venv/bin
Using /lib-repository/.venv/lib/python3.8/site-packages
Searching for certifi==2021.10.8
Best match: certifi 2021.10.8
Adding certifi 2021.10.8 to easy-install.pth file
Using /lib-repository/.venv/lib/python3.8/site-packages
Searching for urllib3==1.26.8
Best match: urllib3 1.26.8
Adding urllib3 1.26.8 to easy-install.pth file
Using /lib-repository/.venv/lib/python3.8/site-packages
Finished processing dependencies for myapi==0.1.0
(.vevn) $ pip list
Package Version
------------------ ---------
build 0.7.0
certifi 2021.10.8
charset-normalizer 2.0.10
idna 3.3
packaging 21.3
pep517 0.12.0
pip 20.0.2
pkg-resources 0.0.0
pyparsing 3.0.6
myapi 0.1.0
requests 2.27.1
setuptools 44.0.0
tomli 2.0.0
urllib3 1.26.8
But when I try to import it, I get a ModuleNotFoundError exception:
(.venv) $ python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'myapi'
>>>
The pip install command works just fine after the setup.py install
(.venv) $ pip install --upgrade --no-index --find-links /lib-repository/python/packages/myapiclient/ myapi
Looking in links: /lib-repository/python/packages/myapiclient/
Requirement already up-to-date: myapi in ./.venv/lib/python3.8/site-packages/myapi-0.1.0-py3.8.egg (0.1.0)
Requirement already satisfied, skipping upgrade: requests in ./.venv/lib/python3.8/site-packages (from myapi) (2.27.1)
Requirement already satisfied, skipping upgrade: idna<4,>=2.5; python_version >= "3" in ./.venv/lib/python3.8/site-packages (from requests->myapi) (3.3)
Requirement already satisfied, skipping upgrade: charset-normalizer~=2.0.0; python_version >= "3" in ./.venv/lib/python3.8/site-packages (from requests->myapi) (2.0.10)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in ./.venv/lib/python3.8/site-packages (from requests->myapi) (2021.10.8)
Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in ./.venv/lib/python3.8/site-packages (from requests->myapi) (1.26.8)
(.venv) $
What am I missing here ?
Well.. after some trial and error, i found a solution:
(.venv) $ pip3 install /lib-repository/python/packages/myapiclient/
You just need to run the install command pointing to the directory containing the setup.py file.
No nee to use --no-index or --find-links in this case.
Now I have everything in place! :)
Thank you very much!

Errors while installing matplotlib using pip install

I updated my Python3 to Python 3.10. It still is showing Python 3.8 as my current version. but that's not the issue. My issue is that when I went to install the matplotlib package using pip install matplotlib, I got some errors. I also tried running pip3 install matplotlib. I got the following errors:
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 0x1057db7c0>: Failed to establish a new connection: [Errno
8] nodename nor servname provided, or not known')':
/simple/matplotlib/
ERROR: Could not find a version that satisfies the requirement
matplotlib (from versions: none) ERROR: No matching distribution found
for matplotlib
The I tried running /Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip and got the following error:
Defaulting to user installation because normal site-packages is not
writeable.
Requirement already up-to-date: pip in
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages
(20.2.3)
I don't get it. It wanted me to upgrade pip and then says it's already up to date?
I just need the matplotlib module installed for my Python scripts.
If you are trying to install matplotlib in your organisation laptop then your organsiation could be blocking the network to connect and download the package. This is one reason its showing retrying error message. You can try disconnecting vpn if you are connecting with any and retry installing it. This error is due to network issue only.

Skipping pyspark pip package when I want to insatlll other packages

I am trying to install apcjckage named elephas by using its wheel file on windows, however. it has some requirments for pyspark and kers, I cant install pyspark on my anaconda due to firewall isssues on my PC. I have juts unzip pyspark and I am using it but , I want to know if there is anyway to skip the pyspark when installing elephas.
(base) C:\Users\Public>python -m pip install elephas-0.4.2-py3-none-any.whl
Processing c:\users\public\elephas-0.4.2-py3-none-any.whl
Requirement already satisfied: hyperas in c:\users\kmob\appdata\local\continuum\anaconda3\lib\site-packages (from elephas==0.4.2) (0.4.1)
Requirement already satisfied: keras in c:\users\kmob\appdata\local\continuum\anaconda3\lib\site-packages\keras-2.2.4-py3.7.egg (from elephas==0.4.2) (2.2.4)
Requirement already satisfied: flask in c:\users\kmob\appdata\local\continuum\anaconda3\lib\site-packages (from elephas==0.4.2) (1.1.1)
Requirement already satisfied: cython in c:\users\kmob\appdata\local\continuum\anaconda3\lib\site-packages (from elephas==0.4.2) (0.29.12)
Requirement already satisfied: tensorflow in c:\users\kmob\appdata\local\continuum\anaconda3\lib\site-packages (from elephas==0.4.2) (1.14.0)
Collecting pyspark (from elephas==0.4.2)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000044F8358>, 'Connection to pypi.org timed out. (con
nect timeout=15)')': /simple/pyspark/
it cant download pyspark from the source since I have firewall, I have pyspark unzipped on my local machine and I can run it, is there anyway to skip the above pyspark installation check?

SSL certificate verify failed and permission error on Install Certificates.command

I'm trying to run
from urllib.request import urlretrieve
url = "https://www.cs.cmu.edu/~./enron/enron_mail_20150507.tgz"
urlretrieve(url, filename="../enron_mail_20150507.tgz")
to download the dataset. I get an SSL certificate verify fail error, which is solved in this question: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) by running
/Applications/Python\ 3.6/Install\ Certificates.command
This gives me an error:
-- pip install --upgrade certifi
Collecting certifi
Using cached https://files.pythonhosted.org/packages/56/9d/1d02dd80bc4cd955f98980f28c5ee2200e1209292d5f9e9cc8d030d18655/certifi-2018.10.15-py2.py3-none-any.whl
Installing collected packages: certifi
Found existing installation: certifi 2018.4.16
Uninstalling certifi-2018.4.16:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/certifi-2018.4.16.dist-info/DESCRIPTION.rst'
Consider using the `--user` option or check the permissions.
I tried changing the command code but its write-protected so I figured I shouldn't mess with it. So I ran
pip install --upgrade certifi
and it updated, but when I try to download the Enron data again I still get the same message. It seems as if the command gets caught up on the older version of certifi. I have Python 2.7 and 3.6 on this computer for some reason so I ran pip3 because that works sometimes but still am getting the same error.

Resources